i have a grid view that i fill it with C# and the user edit it and then i insert it on a diffrent table, when i insert it it takes the changes the user done in the first row and ignor all the chagnes in the other rows. the C3 colum is the column the user edit
this is the datagrid genration query
string output = "select distinct [C1],C2 as [Error_Name], '' as [C3], [C4],[C5] from rejection";
SqlCommand cmd2 = new SqlCommand();
cmd2.CommandType = CommandType.Text;
cmd2.CommandText = output;
cmd2.Connection = conne;
conne.Open();
SqlDataAdapter dscmd = new SqlDataAdapter(output, strconnection);
DataSet ds = new DataSet();
dscmd.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
this is the inserting query
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
string StrQuery = @"INSERT INTO [test2] VALUES ('" + dataGridView1.Rows[i].Cells[0].Value + "', '" + dataGridView1.Rows[i].Cells[1].Value + "', '" + dataGridView1.Rows[i].Cells[2].Value + "', '" + dataGridView1.Rows[i].Cells[3].Value + "', '" + dataGridView1.Rows[i].Cells[4].Value + "');";
SqlConnection conn = new SqlConnection(strconnection);
conn.Open();
using (SqlCommand comm = new SqlCommand(StrQuery, conn))
{
comm.ExecuteNonQuery();
}
conn.Close();
Note all the rows are inserted on the database, but the first row only have the edit chagnes all other rows dont have the edit changes they are the same.
when i use this connection string :
string strconnection = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\ksa\Documents\Visual Studio 2012\Projects\test\test\test.mdf;Integrated Security=True";
it works ...... but when i use the app.sitting so its :
string strconnection = ConfigurationManager.ConnectionStrings["test"].ConnectionString;
and in the app sitting :
<connectionStrings>
<add name="test" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\test.mdf;Integrated Security=True" providerName="Microsoft.SqlServerCe.Client.4.0" />
</connectionStrings>
it doesnt work !!