i cant able to insert values using the code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jrkarthi
    New Member
    • Mar 2009
    • 1

    i cant able to insert values using the code

    Code:
    dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\KarthI\sample\db1\WindowsApplication1\WindowsApplication1\bin\Debug\phm_pharmacy.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
    con.Open()
            Dim cmd As New SqlCommand
            cmd.CommandText = "insert into quotation_t11 values('" & TextBox1.Text & "','" & ComboBox1.SelectedItem & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"
            cmd.Connection = con
            cmd.ExecuteNonQuery()
            MsgBox("Insertion process is success")
            con.Close()
    When i run this code it showing insertion process is sucess but i cant able to see the value inside the table....
    created table using microsoft sql database file
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    Hi, try this code:

    Code:
    dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\KarthI\sample\db1\WindowsApplication1\WindowsApplication1\bin\Debug\phm_pharmacy.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
    Dim strInsertQuery As String = “insert into quotation_t11 values('" & TextBox1.Text & "','" & ComboBox1.SelectedItem & "','" & TextBox2.Text & "','" & TextBox3.Text & "')" 
    Dim cmdInsertCommand As New SqlCommand(strInsertQuery, con) 
    con.Open() 
    cmdInsertCommand.ExecuteNonQuery()
    con.Close()
    Steven

    Comment

    • aryanbs
      New Member
      • Mar 2009
      • 42

      #3
      Try MrMancunian code!

      Make sure, the file is not being overwriten by application main folder's mdf, to check that, look in Solution Explorer, your mdf's proerties, copy to output Directory, change it to never

      Also Check whether cmd.ExecuteNonQ uery() is returning value 1 or not

      Dim cnt as Integer=cmd.Exe cuteNonQuery()
      Messagebox.Show (cnt.ToString() )

      Comment

      Working...