Datagrids and Textboxes

To retrive the data to unbound textboxes it goes as follows:

        
       With datagrid 
            textbox1= .Item(.CurrentCell.RowNumber, 0) 
            textbox2= .Item(.CurrentCell.RowNumber, 1) 
        End With 

If you want to update the database, well there’s 2 ways. An update command in your code or a stored procedure in the db that you call. Stored procedures are much more efficient so I always use them.

Stored procedure way:

 
        Dim sql_Conn As New SqlClient.SqlConnection(ConnectionString) 
        Dim sqlcmd_Make As SqlCommand = New _ 
            SqlCommand("UPDATE_MAKE", sql_Conn) 

        With sqlcmd_Make 
            .CommandType = CommandType.StoredProcedure 

            With .Parameters 
                .Add("@MAKE_ID", SqlDbType.VarChar, 12).Value = l_l_MakeId 
                .Add("@DESC", SqlDbType.VarChar, 15).Value = tbMake.Text 
            End With 
        End With 

        sql_Conn.Open() 
        sqlcmd_Make.ExecuteNonQuery() 


what I think the in code update way is:


        Dim sql_Conn As New SqlClient.SqlConnection(ConnectionString) 
        Dim sqlcmd_Make As SqlCommand = New _ 
            SqlCommand("update command", sql_Conn) 

        sql_Conn.Open() 
        sqlcmd_Make.ExecuteNonQuery() 

to refresh your datagrid without going from scratch:


    dataset.Clear() 
                sqladapter.Fill(dataset, "TABLENAME")