8 Replies - 512 Views - Last Post: 02 July 2013 - 10:47 PM Rate Topic: -----

#1 Kaushik0007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-June 13

data not inserted in database

Posted 02 July 2013 - 02:12 AM

code work perfectly but not inserted in database table as desired when using sql query string.

Dim con As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db\Atul.mdf;Integrated Security=True;User Instance=True")
        con.Open()
        Dim cmd As SqlCommand = New SqlCommand("INSERT INTO consumer(name, houseno, contact, W_S_connection, account, catagory, ferrulsize, tapes, metermake, metersize, meterno, toiletseat)" & _
                        "VALUES (@name, @houseno, @contact, @W_S_connection, @account, @catagory, @ferrulsize, @tapes, @metermake, @metersize, @meterno, @toiletseat)")
        cmd.Parameters.AddWithValue("@name", NameTextBox.Text)
        cmd.Parameters.AddWithValue("@houseno", HousenoTextBox.Text)
        cmd.Parameters.AddWithValue("@contact", ContactTextBox.Text)
        cmd.Parameters.AddWithValue("@W_S_connection", W_S_connectionTextBox.Text)
        cmd.Parameters.AddWithValue("@account", AccountTextBox.Text)
        cmd.Parameters.AddWithValue("@catagory", CatagoryComboBox.Text)
        cmd.Parameters.AddWithValue("@ferrulsize", FerrulsizeTextBox.Text)
        cmd.Parameters.AddWithValue("@tapes", TapesTextBox.Text)
        cmd.Parameters.AddWithValue("@metermake", MetermakeTextBox.Text)
        cmd.Parameters.AddWithValue("@metersize", MetersizeTextBox.Text)
        cmd.Parameters.AddWithValue("@meterno", MeternoTextBox.Text)
        cmd.Parameters.AddWithValue("@toiletseat", ToiletseatTextBox.Text)
        cmd.Connection = con
        cmd.ExecuteNonQuery()
        MessageBox.Show("Value Inserted Successfully")
        NameTextBox.Text = ""
        HousenoTextBox.Text = ""
        ContactTextBox.Text = ""
        W_S_connectionTextBox.Text = ""
        AccountTextBox.Text = ""
        CatagoryComboBox.SelectedText = ""
        FerrulsizeTextBox.Text = ""
        TapesTextBox.Text = ""
        MetermakeTextBox.Text = ""
        MetersizeTextBox.Text = ""
        MeternoTextBox.Text = ""
        ToiletseatTextBox.Text = ""


Is This A Good Question/Topic? 0
  • +

Replies To: data not inserted in database

#2 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: data not inserted in database

Posted 02 July 2013 - 02:31 AM

have you used try and catch exception.
Was This Post Helpful? 0
  • +
  • -

#3 Kaushik0007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-June 13

Re: data not inserted in database

Posted 02 July 2013 - 03:33 AM

as try ints working like before
 Dim con As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db\Atul.mdf;Integrated Security=True;User Instance=True")
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addition.Click
        con.Open()
        Try
            Dim cmd As SqlCommand = New SqlCommand("INSERT INTO consumer(name, houseno, contact, W_S_connection, account, catagory, ferrulsize, tapes, metermake, metersize, meterno, toiletseat)" & _
                        "VALUES (@name, @houseno, @contact, @W_S_connection, @account, @catagory, @ferrulsize, @tapes, @metermake, @metersize, @meterno, @toiletseat)")
            cmd.Parameters.AddWithValue("@name", NameTextBox.Text)
            cmd.Parameters.AddWithValue("@houseno", HousenoTextBox.Text)
            cmd.Parameters.AddWithValue("@contact", ContactTextBox.Text)
            cmd.Parameters.AddWithValue("@W_S_connection", W_S_connectionTextBox.Text)
            cmd.Parameters.AddWithValue("@account", AccountTextBox.Text)
            cmd.Parameters.AddWithValue("@catagory", CatagoryComboBox.Text)
            cmd.Parameters.AddWithValue("@ferrulsize", FerrulsizeTextBox.Text)
            cmd.Parameters.AddWithValue("@tapes", TapesTextBox.Text)
            cmd.Parameters.AddWithValue("@metermake", MetermakeTextBox.Text)
            cmd.Parameters.AddWithValue("@metersize", MetersizeTextBox.Text)
            cmd.Parameters.AddWithValue("@meterno", MeternoTextBox.Text)
            cmd.Parameters.AddWithValue("@toiletseat", ToiletseatTextBox.Text)
            cmd.Connection = con
            cmd.ExecuteNonQuery()
            'MessageBox.Show("Value Inserted Successfully")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        NameTextBox.Text = ""
        HousenoTextBox.Text = ""
        ContactTextBox.Text = ""
        W_S_connectionTextBox.Text = ""
        AccountTextBox.Text = ""
        CatagoryComboBox.SelectedText = ""
        FerrulsizeTextBox.Text = ""
        TapesTextBox.Text = ""
        MetermakeTextBox.Text = ""
        MetersizeTextBox.Text = ""
        MeternoTextBox.Text = ""
        ToiletseatTextBox.Text = ""
    End Sub

errors image are attached
after submit the form Attached Image
after sql query Attached Image
Was This Post Helpful? 0
  • +
  • -

#4 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: data not inserted in database

Posted 02 July 2013 - 03:44 AM

assign connection to cmd before adding value
cmd.Connection = con
cmd.Parameters.AddWithValue("@name", NameTextBox.Text)




or u can do this too
Dim cmd As SqlCommand = New SqlCommand("INSERT INTO consumer(name, houseno, contact, W_S_connection, account, catagory, ferrulsize, tapes, metermake, metersize, meterno, toiletseat)" & _
06
                       "VALUES (@name, @houseno, @contact, @W_S_connection, @account, @catagory, @ferrulsize, @tapes, @metermake, @metersize, @meterno, @toiletseat)",cn)


This post has been edited by vks.gautam1: 02 July 2013 - 03:55 AM

Was This Post Helpful? 0
  • +
  • -

#5 Kaushik0007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-June 13

Re: data not inserted in database

Posted 02 July 2013 - 09:26 PM

still not get data in database........
Was This Post Helpful? 0
  • +
  • -

#6 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: data not inserted in database

Posted 02 July 2013 - 10:11 PM

View PostKaushik0007, on 02 July 2013 - 09:26 PM, said:

still not get data in database........

where you declared your connection
Dim con As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db\Atul.mdf;Integrated Security=True;User Instance=True")




wt is your current code . can you show?

This post has been edited by vks.gautam1: 02 July 2013 - 10:31 PM

Was This Post Helpful? 0
  • +
  • -

#7 Kaushik0007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-June 13

Re: data not inserted in database

Posted 02 July 2013 - 10:37 PM

Dim con As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db\Atul.mdf;Integrated Security=True;User Instance=True")
        con.Open()
        Try
            Dim cmd As SqlCommand = New SqlCommand("INSERT INTO Consumer(name, houseno, contact, W_S_connection, account, category, ferrulsize, tapes, metermake, metersize, meterno, toiletseat)" & _
                        "VALUES (@name, @houseno, @contact, @W_S_connection, @account, @category, @ferrulsize, @tapes, @metermake, @metersize, @meterno, @toiletseat)", con)
            'cmd.Connection = con
            cmd.Parameters.AddWithValue("@name", NameTextBox.Text)
            cmd.Parameters.AddWithValue("@houseno", HousenoTextBox.Text)
            cmd.Parameters.AddWithValue("@contact", ContactTextBox.Text)
            cmd.Parameters.AddWithValue("@W_S_connection", W_S_connectionTextBox.Text)
            cmd.Parameters.AddWithValue("@account", AccountTextBox.Text)
            cmd.Parameters.AddWithValue("@category", CatagoryComboBox.Text)
            cmd.Parameters.AddWithValue("@ferrulsize", FerrulsizeTextBox.Text)
            cmd.Parameters.AddWithValue("@tapes", TapesTextBox.Text)
            cmd.Parameters.AddWithValue("@metermake", MetermakeTextBox.Text)
            cmd.Parameters.AddWithValue("@metersize", MetersizeTextBox.Text)
            cmd.Parameters.AddWithValue("@meterno", MeternoTextBox.Text)
            cmd.Parameters.AddWithValue("@toiletseat", ToiletseatTextBox.Text)
            cmd.ExecuteNonQuery()
            MessageBox.Show("Value Inserted Successfully")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        NameTextBox.Text = ""
        HousenoTextBox.Text = ""
        ContactTextBox.Text = ""
        W_S_connectionTextBox.Text = ""
        AccountTextBox.Text = ""
        CatagoryComboBox.SelectedText = ""
        FerrulsizeTextBox.Text = ""
        TapesTextBox.Text = ""
        MetermakeTextBox.Text = ""
        MetersizeTextBox.Text = ""
        MeternoTextBox.Text = ""
        ToiletseatTextBox.Text = ""

Was This Post Helpful? 0
  • +
  • -

#8 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: data not inserted in database

Posted 02 July 2013 - 10:41 PM

declare your connection in button click event
Dim con As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db\Atul.mdf;Integrated Security=True;User Instance=True")

        con.Open()



Was This Post Helpful? 0
  • +
  • -

#9 Kaushik0007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 11-June 13

Re: data not inserted in database

Posted 02 July 2013 - 10:47 PM

using it on button
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1