This is code to insert Grid details in vb.net you can use this function in common class.

you also need to declare required variable globally.

public Boolean InsertGridDetails(ref DataTable dt, string TableName, String PkValue, string PkName,SqlTransaction SqlTrans,SqlConnection Cn)
    {
        try
        {
            string query = "";
            query = "select * from " + TableName + " where " + PkName + " = '" + PkValue + "'";
            cmd = new SqlCommand(query, Cn);
            cmd.Transaction = SqlTrans;
            DA = new SqlDataAdapter(cmd);
            SqlCommandBuilder GridDetail = new SqlCommandBuilder(DA);
            DA.Update(dt);
            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
                     cmd.Dispose();
            DA.Dispose();
        }
    }


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

No comments