-1

I am new in vb.net, sql and even record data in phpmyadmin. When I add the records using my interface, I checked my phpmyadmin and it was indicating to have an entry in the table meaning my vb.net and phpmyadmin is connected but the values returned NULL. How can I make it not NULL? instead ,records the desired data?

This is my code:

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)

This what my table looks like in phpmyadmin:

http://i1182.photobucket.com/albums/x454/catherinefbalauro/Untitled.png

Any help would be appreciated. Thanks! :)

1
  • ALREADY SOLVED BY ME :)) [CLOSED] Commented Jul 26, 2012 at 1:21

1 Answer 1

0

Do something like this:

' 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
Sign up to request clarification or add additional context in comments.

3 Comments

vb.net cannot accept .addwithvalue as it said that it is not member of MySqlParameterCollection o.o
no, is should have work..look at this code stackoverflow.com/a/10524452/491243
syntax of C# and vb is not the same right? when i try your suggestion it said is not member of mysqlparameter. what my code accept is like this one: .Parameters.Add(New MySqlParameter("@bednumber", txtbednum.Text)) but still NULL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.