How to use sql parameters for a select query?

前端 未结 3 974
孤城傲影
孤城傲影 2021-01-21 07:59

I need to fetch the records based on a \'like\' match against a set of records,

The below query im using is not working . Does anyone knows what\'s wrong with the query?

3条回答
  •  失恋的感觉
    2021-01-21 08:43

    If Not con.State = ConnectionState.Open Then con.Open() End If

        Try
    
            Dim cmd As New OleDbCommand("UPDATE med_records SET Medicine=@Medicine,Dosage=@Dosage,Format=@Format,Expiration_date=@Expiration_date,Quantity=@Quantity where M_id=@M_id", con)
            cmd.Parameters.AddWithValue("@Medicine", txtMedicine.Text)
            cmd.Parameters.AddWithValue("@Dosage", txt_Dosage.Text)
            cmd.Parameters.AddWithValue("@Format", txt_Format.Text)
            cmd.Parameters.AddWithValue("@Expiration_date", txt_Expirationdate.Text)
            cmd.Parameters.AddWithValue("@Quantity", NumericUpDown1.Text)
            cmd.Parameters.AddWithValue("@M_id", txt_M_id.Text)
            cmd.ExecuteNonQuery()
            MsgBox("Update data")
            con.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
    
        End Try
    

提交回复
热议问题