ok..
i have sample code whcih updates the grid rows into the DB table but it uses a Stored procedure.
Here it is : maybe u can modify it to suit ur appl.
This is the code in teh save button click event handler:
DataSet objDataSet = new DataSet();
objDataAdapter.Fill(objDataSet);
grdExcel.DataSource = objDataSet.Tables[0].DefaultView;
grdExcel.DataBind();
////
SqlConnection conn = new SqlConnection(connstring);
conn.Open();
SqlCommand comm = new SqlCommand("sp_insert", conn);
comm.CommandType = CommandType.StoredProcedure;
int i;
for (i = 0; i <= grdExcel.Rows.Count - 1; i++)
{
comm.Parameters.Add("@lastname", SqlDbType.VarChar).Value =objDataSet .Tables [0].Rows[i][0].ToString ();
comm.Parameters.Add("@firstname", SqlDbType.VarChar).Value = objDataSet.Tables[0].Rows[i][1].ToString();
comm.Parameters.Add("@address1", SqlDbType.VarChar).Value = objDataSet.Tables[0].Rows[i][2].ToString();
comm.Parameters.Add("@address2", SqlDbType.VarChar).Value = objDataSet.Tables[0].Rows[i][3].ToString();
comm.Parameters.Add("@city", SqlDbType.VarChar).Value = objDataSet.Tables[0].Rows[i][4].ToString();
comm.Parameters.Add("@state", SqlDbType.VarChar).Value = objDataSet.Tables[0].Rows[i][5].ToString();
comm.Parameters.Add("@zip", SqlDbType.VarChar).Value = objDataSet.Tables[0].Rows[i][6].ToString();
comm.Parameters.Add("@phone", SqlDbType.VarChar).Value = objDataSet.Tables[0].Rows[i][7].ToString();
comm.Parameters.Add("@fax", SqlDbType.VarChar).Value = objDataSet.Tables[0].Rows[i][8].ToString();
comm.Parameters.Add("@email", SqlDbType.VarChar).Value = objDataSet.Tables[0].Rows[i][9].ToString();
comm.Parameters.Add("@website", SqlDbType.VarChar).Value = objDataSet.Tables[0].Rows[i][10].ToString();
int rows;
rows = comm.ExecuteNonQuery();
comm.Parameters.Clear();
}
Sp_Insert is teh stored procedure im using.
create proc [dbo].[sp_insert](
@lastname varchar(50),
@firstname varchar(50),
@address1 varchar(50),
@address2 varchar(50),
@city varchar(50),
@state varchar(50),
@zip varchar(50),
@phone varchar(50),
@fax varchar(50),
@email varchar(50),
@website varchar(50)) as
INSERT INTO [Ann].[dbo].[Members]
([lastname]
,[firstname]
,[address1]
,[address2]
,[city]
,[state]
,[zip]
,[phone]
,[fax]
,[email]
,[website]
)
VALUES
(@lastname
,@firstname
,@address1
,@address2
,@city
,@state
,@zip
,@phone
,@fax
,@email
,@website
);
select scope_identity()
i managed to fix the errors now it's working with no errors, but it's still not working although the program is telling me that the database has been updated but when i check the database, inputs in datagridview didn't save while the inputs for textboxes are there in the database. Can you give me a sample code on how to fix this? tyvm.