Hi, i'm still newbie in C# programming. I need some help on my project.
I have datagridview that i fill it with couple data from different table in my database, the column in my datagridview is Choose(checkbox column), Item(textbox column) and Detail(textbox column).
what i want to do is, when user
checked the checkbox in a row or more in Choose column it will saved the checked row as new record in my new database.
here little part of my code to execute that,
DataTable dtChanged = ((DataTable)dgvItem.DataSource).GetChanges();
if (dtChanged == null)
return;
SqlConnection sqlConn = new SqlConnection(GlobalVar.gstrConnStr);
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand();
foreach (DataRow drChanged in dtChanged.Rows)
{
if (!(Boolean)drChanged["Choosen"])
continue;
if (drChanged["Choosen"].ToString() == "True")
{
string strSeq = drChanged["Choosen"].ToString();
string strItemID = drChanged["Items"].ToString().Replace("'", "''");
string strSql = string.Format("INSERT INTO mkar1(meID,meSeq,meItemID,meUser,meDate)" +
"VALUES ('{0}',{1},'{2}','{3}','{4:yyyy/MM/dd HH:mm:ss}')",
txtNIKmkar.Text.Trim().Replace("'", "''"), strSeq, strItemID, GlobalVar.gstrConnStr, DateTime.Now);
sqlCmd.CommandText = strSql;
sqlCmd.Connection = sqlConn;
sqlCmd.ExecuteNonQuery();
}
}
sqlCmd.Dispose();
sqlConn.Close();
sqlConn.Dispose();
i know the code i write is still have problem and i need some help to fix it because i dont know how to do it.
and the database i will going to use,
meID (PK, nchar 15, not null)
meSeq (PK, tinyint, not null)
meItemID (nchar 10, not null)
meUser (nchar 20, not null)
meDate (datetime, not null)
And here is my question,
1. how to save into the database?
2. as for the column "meSeq" i have to save numeric number start from 0 for every checked row. how can i save every checked row as new record?
what i need to do?
please help, i will greatly appreciate every answer.