我是 vb.net、sql 的新手,甚至在 phpmyadmin 中记录数据。当我使用我的界面添加记录时,我检查了我的 phpmyadmin,它表明表中有一个条目,这意味着我的 vb.net 和 phpmyadmin 已连接,但值返回 NULL。我怎样才能使它不为NULL?相反,记录所需的数据?
这是我的代码:
Dim ServerString As String = "Server=localhost; database=patientinfo;user id=root;password="
Dim SQLConnection As New MySqlConnection()
Public Sub SaveInfos(ByRef SQLStatement As String)
Dim cmd As MySqlCommand = New MySqlCommand
With cmd
.CommandText = SQLStatement
.CommandType = CommandType.Text
.Connection = SQLConnection
.ExecuteNonQuery()
End With
SQLConnection.Close()
'MsgBox("Successfully Added!")
MsgBox("Successfully Saved")
Me.Visible = False
Mainform.Show()
SQLConnection.Dispose()
End Sub
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Try
'===========================Add New Patient========================================
bednumber = txtbednum.Text
patient_name = txtName.Text
patient_age = Convert.ToInt32(txtAge.Text)
date_of_confinement = Date.Parse(dtpDate.Value)
type_of_sickness = txtSickness.Text
type_of_IV_fluid = txtFluid.Text
number_of_bottles = Convert.ToInt32(txtBottle.Text)
drop_rate = Convert.ToInt32(txtDrop.Text)
'To check if all values have been filled up
If patient_name = "" Or patient_age = "" Or date_of_confinement = "" _
Or type_of_sickness = "" Or type_of_IV_fluid = "" Or number_of_bottles = "" Or drop_rate = "" _
Then
MsgBox("Please Complete All the Required Fields")
Else
Dim SQLStatement As String = "INSERT INTO patient(bednumber, name, age, date_of_confinement,type_of_sickness, type_of_IV_fluid, number_of_bottles, drop_rate) VALUES(@bednumber, @name, @age, @date_of_confinement, @type_of_sickness, @type_of_IV_fluid, @number_of_bottles, @drop_rate)"
SaveInfos(SQLStatement)
这是我的表在 phpmyadmin 中的样子:
http://i1182.photobucket.com/albums/x454/catherinefbalauro/Untitled.png
任何帮助,将不胜感激。谢谢!:)