插入数据库不起作用

时间:2014-04-23 19:04:32

标签: sql-server vb.net ado.net

我目前正在处理我的程序但我遇到了一个问题,当我将数据插入数据库时​​,当我使用简单的表单数据进入时,但每次我使用像绑定源,ex:来检索患者ID,即使查询有效,我也无法将数据保存到数据库中。我需要花一个星期的时间帮忙。

这是我的代码:

'Connection to the database
Dim con As New SqlConnection
con.ConnectionString = My.Settings.NateCare_DBConnectionString
'open the connection
con.Open()

Try
   Dim insrtqry As String = "Insert into Consultation Values(@Consult_ID, @Disease_name, @Symptoms, @Consultation_price, @Employee_ID, @App_ID)"
   Dim insertCmd As New SqlCommand(insrtqry, con)

   'insert in Consultation
   insertCmd.Parameters.Add("@Consult_id", SqlDbType.VarChar, 10).Value = Me.txtconsultationid.Text
   insertCmd.Parameters.Add("@Disease_name", SqlDbType.VarChar, 25).Value = Me.txtdiagnosis.Text
   insertCmd.Parameters.Add("@Symptoms", SqlDbType.VarChar, 50).Value = Me.txtsymptomes.Text
   insertCmd.Parameters.Add("@Consultation_price", SqlDbType.Decimal).Value = Me.txtconsultationprice.Text
   insertCmd.Parameters.Add("@Employee_id", SqlDbType.VarChar, 6).Value = Me.txtemployeeid.Text
   insertCmd.Parameters.Add("@App_id", SqlDbType.VarChar, 7).Value = Me.cmbAppointmentId.SelectedValue

   Dim count As Integer = 0
   count = insertCmd.ExecuteNonQuery()
   'disposition of memory
   insertCmd.Dispose()

   If count >= 1 Then
      MessageBox.Show("Consultation Details Inserted Successfully", "Nat Care Management System", MessageBoxButtons.OK, MessageBoxIcon.Information)

      clear()
      'close connection after insertion
      Me.ConsultationBindingSource.EndEdit()
      Me.ConsultationTableAdapter.Update(NateCare_DBDataSet.Consultation)
      Me.TableAdapterManager.UpdateAll(NateCare_DBDataSet)

   End If
Catch ex As SqlException
   MsgBox(ex.Message, CType(ex.ErrorCode, MsgBoxStyle), ex.InnerException)
End Try

0 个答案:

没有答案