title: I can't delete a row from MS access database from VB.net
body: <p>I'm trying to delete a row from MS database by following a <a href="https://www.youtube.com/watch?v=nse-xeFp0Og" rel="nofollow noreferrer">YT tutorial</a> but I got 2 kinds of errors. When I try this:</p>
  <pre><code>    Dim provider As String
      Dim dataFile As String
      Dim connString As String
      Dim myConnection As OleDbConnection = New OleDbConnection
  
      provider = &quot;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=&quot;
          dataFile = &quot;C:\Users\user\Desktop\PU\SEMESTER 4\Visual Programming\Hospital Databases\Patient DB.accdb&quot;
      connString = provider &amp; dataFile
      myConnection.ConnectionString = connString
      myConnection.Open()
      Dim str As String
      str = &quot;Delete * from [Patient] Where [PatientID] = &quot; &amp; PatientID.ToString &amp; &quot;&quot;
      Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
  </code></pre>
  <p>I got this error: &quot;Malformed GUID in query expression '[PatientID]=DataGridViewTextBoxColumn { Name=PatientID, index=0 } '</p>
  <p>So I used brackets as stated <a href="https://docs.microsoft.com/en-us/office/troubleshoot/access/error-using-special-characters" rel="nofollow noreferrer">here</a> so now it's like this:</p>
  <pre><code>str = &quot;Delete * from [Patient] Where [PatientID] = [&quot; &amp; PatientID.ToString &amp; &quot;]&quot;
  </code></pre>
  <p>But this gave an error: &quot;No value given for one or more required parameters&quot;. When I replaced the brackets with single quotes I also get this error.</p>
  <p>I tried <a href="https://stackoverflow.com/questions/2378763/no-value-given-for-one-or-more-required-parameters/2378853">this</a>, <a href="https://stackoverflow.com/questions/11519195/how-to-delete-records-of-ms-access-database-using-vb-net-form-and-how-to-enter-a">this</a>, and <a href="https://stackoverflow.com/questions/62502653/delete-selected-row-from-datagridview-and-ms-access-database">this</a> but still got an error.</p>
  <p>Idk what to do.</p>
  <p>EDIT:</p>
  <p>I did <code>PatientID.ToString</code> because I want to make it so that when a user clicks on an ID cell, it will get the ID without the user having to input anything. But apparently that was wrong so I made an inputbox and followed Mary's answer. But I got this error on the <code>Execute...</code> line:
  &quot;No value given for one or more required parameters&quot;</p>
  <p>I searched and most of them said to put single quotes for it to work. I did (^) and still got that error :( Did I call the sub in the wrong way?</p>
  <pre><code>    Private Sub DischargeToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles DischargeToolStripMenuItem1.Click
          Dim ID As Integer
          ID = InputBox(&quot;Enter the ID of the patient to be discharged&quot;, &quot;Discharge&quot;)
          DeleteRecord(ID)
      End Sub
  
      Sub DeleteRecord(ID As Integer)
          Dim provider = &quot;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=&quot;
          Dim dataFile = &quot;C:\Users\user\Desktop\PU\SEMESTER 4\Visual Programming\Hospital Databases\Patient DB.accdb&quot;
          Dim connString = provider &amp; dataFile
          Using myConnection As New OleDbConnection(connString),
                  cmd As New OleDbCommand(&quot;Delete * from Patient Where PatientID = @ID&quot;, myConnection)
              cmd.Parameters.Add(&quot;@ID&quot;, OleDbType.Integer).Value = ID
              myConnection.Open()
              cmd.ExecuteNonQuery()
          End Using
      End Sub
  </code></pre>