-1

私は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

どんな助けでもいただければ幸いです。ありがとう!:)

4

1 に答える 1

0

次のようにします。

' Assuming that your SQLStatement is as follow
' INSERT INTO MyTableName 
' VALUES (  @bednumber, @name, @age, 
'           @date_of_confinement,@type_of_sickness,
'           @type_of_IV_fluid, @number_Of_Bottles,
'           @drop_rate
'        )
With cmd
    .CommandText = SQLStatement
    .CommandType = CommandType.Text
    .Connection = SQLConnection

    .Parameters.AddWithValue("@bednumber", txtbednum.Text)
    .Parameters.AddWithValue("@name", txtName.Text)
    .Parameters.AddWithValue("@age", txtAge.Text)
    ' dothe same until
    ' you have added allthe parameter
    ' with values

    SQLConnection.Open()
    .ExecuteNonQuery()
End With
于 2012-07-24T14:56:47.337 に答える