Click here to Skip to main content
15,886,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#.net .. I am not getting how to read values from datagridview columns and rows and insert them in sql server db table..............

string str2= Convert.ToDecimal(row.Cells[3].Value);


i am not getting, how to write proper code for that .........
this my code of application .....

con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Insertsalesorder";
cmd.CommandType = CommandType.StoredProcedure;


dataGridView1.DataSource = ds.Tables[0];
DataTable dt = new DataTable();
DataRow dr = ds.Tables[0].NewRow();
dr[0] = txtsbill.Text;
dr[1] = txtsgrandtot.Text;
dr[2] = cbscust.SelectedItem;
dr[3] = txtshmm.Text;
ds.Tables[0].Rows.Add(dr);
MessageBox.Show("Record Added");

if(ds.Tables[0].Rows.Count >0)



//ds.Tables[0].Rows[rno][1] = textBox2.Text;
//ds.Tables[0].Rows[rno][2] = textBox3.Text;
//ds.Tables[0].Rows[rno][3] = textBox4.Text;
//MessageBox.Show("Record Modified");
// string str3 = Convert.ToDecimal(row.Cells[4].Value);

cmd.Parameters.AddWithValue("@Billno1", txtsbill.Text);
cmd.Parameters.AddWithValue("@Custname1",cbscust.SelectedItem);
cmd.Parameters.AddWithValue("@Dateofsale1", mtxtdate.Text);
cmd.Parameters.AddWithValue("@HammaliCharge1", txtshmm.Text);
cmd.Parameters.AddWithValue("@TotalAmount1", txtstotamt.Text);
cmd.Parameters.AddWithValue("@SaleTaxPer1", txtstaxper.Text);
cmd.Parameters.AddWithValue("@TaxAmt1 ", txtsaftertaxamt.Text);
cmd.Parameters.AddWithValue("@GrandTotal1", txtsgrandtot.Text);

}


plz provide me the write code for that ....

is there any way to post snap shot or image of my C# form page with this question ........
so it will be useful for understanding the problem..........
Posted
Updated 18-Sep-13 3:58am
v2
Comments
[no name] 18-Sep-13 9:54am    
"proper code for that".. the proper code for what? A decimal data type is not a string.... You need to figure out if you want a decimal or string first.
The Doer 19-Sep-13 0:19am    
i could not find the "WRITE" code for that !!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900