0

这个命令对于插入单个值是否正确,

 "INSERT INTO test (testname) values ('" & txtSelect.Text & "')"

实际上我正在尝试通过此命令插入,但它不起作用..

 "INSERT INTO AdmitPt(Bedcategory, BedNo, BedCharges, PtName, PtAge, Address, PhoneNo, 
 Date, BloodGroup, Doctor, Remarks) VALUES('" & CmbBedType.SelectedItem & "', '" & 
 CmbBedNo.SelectedItem & "', " & txtCharges.Text & "', '" & txtPatName.Text & "', '" & 
 txtPatAge.Text & "', '" & txtPatAdd.Text & "', '" & txtPhone.Text & "', '" & 
 dtpDate.Value.ToShortDateString & "', '" & cmbBloodGrp.SelectedItem & "', '" & 
 cmbDoctor.SelectedItem & "',  " & txtRemarks.Text & ")"

请纠正我我做错了。

4

3 回答 3

0

如果您发布了整个代码 - 您忘记了实际执行命令。添加

comStudent.ExecuteNonQuery()

在关闭连接之前。

于 2013-09-25T05:42:18.317 回答
0

你应该使用Text的属性SelectedItem

 "INSERT INTO AdmitPt(Bedcategory, BedNo, BedCharges, PtName, PtAge, Address, PhoneNo, 
  Date, BloodGroup, Doctor, Remarks) VALUES('" & CmbBedType.SelectedItem.Text & "', '" & 
 CmbBedNo.SelectedItem.Text & "', " & txtCharges.Text & "', '" & txtPatName.Text & "', '" & 
 txtPatAge.Text & "', '" & txtPatAdd.Text & "', '" & txtPhone.Text & "', '" & 
 dtpDate.Value.ToShortDateString() & "', '" & cmbBloodGrp.SelectedItem.Text & "', '" & 
 cmbDoctor.SelectedItem.Text & "', " & txtRemarks.Text & ")"

也是ToShortDateString一种方法,应该写成ToShortDateString()

于 2013-09-24T10:33:51.377 回答
0

不会产生异常,但值不会进入 DB.. 不存储..

code

   Dim RegNo, BedNo, BedType, Charges, PatName, PatAge, PatAddr, Phone, CheckupDate, BloodGroup, Doctor, Remarks As String


    RegNo = txtRegNo.Text
    BedNo = CmbBedNo.SelectedItem.ToString()
    BedType = CmbBedType.SelectedItem.ToString()
    Charges = txtCharges.Text
    PatName = txtPatName.Text
    PatAge = txtPatAge.Text
    PatAddr = txtPatAdd.Text
    Phone = txtPhone.Text
    CheckupDate = dtpDate.Value.ToShortDateString()
    BloodGroup = cmbBloodGrp.SelectedItem.ToString()
    Doctor = cmbDoctor.SelectedItem.ToString()
    Remarks = txtRemarks.Text

    conStudent.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\DBProject\hspms.mdb"
    conStudent.Open()
    comStudent.CommandText = "INSERT INTO AdmitPt(ID, Bedcategory, BedNo, BedCharges, PtName, PtAge, Address, PhoneNo, Date, BloodGroup, Doctor, Remarks) VALUES('" & RegNo & "', '" & BedType & "', '" & BedNo & "', " & Charges & "', '" & PatName & "', '" & PatAge & "', '" & PatAddr & "', '" & Phone & "', '" & CheckupDate & "', '" & BloodGroup & "', '" & Doctor & "',  " & Remarks & ")"
    comStudent.Connection = conStudent
    comStudent.CommandType = CommandType.Text
    conStudent.Close()

code

于 2013-09-25T05:33:14.477 回答