i m using following query for inserting data into my database...
everything is ok
but whenever i restart my form there is no data in my tables :(
do i need to use commit statement ??
if yes then how ?

Private Sub Button1_insert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1_insert.Click
 
        Try
            cn.Open()
            Dim query As String = "insert into Department_Master values('" + TextBox1_deptid.Text + "','" + TextBox2_deptname.Text + "','" + TextBox3_remarks.Text + "') "
            Dim cmd As New SqlCommand(query, cn)

            cmd.ExecuteNonQuery()

            MessageBox.Show("Data Inserted")

        Catch ex As Exception
            MessageBox.Show(ex.ToString())

        Finally

            cn.Close()

        End Try
      End Sub

To get data, you have to create a new command, using SELECT statement.

i am using data grid for retrieving data
cant i get the data on data grid without select statement ?

You need the select statement to retrieve data into a dataset and then the datagrid displays the data in your dataset.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.