Hi Friends,
I am using C# Windows Application.I am displaying SQL data into grid view using for loop Condition.Now, I want to update data(which is display in datagridview) into SQL Database...But it didn't display the newly added data...
here is my sample code Display data in Grid....
comm = "select Name,Rate,Qty,TotalAmount from SALESENTRY where PENo = '" + txt_VocherNo.Text + "'";
SqlCommand sqlcom = new SqlCommand(comm, sqlcon);
SqlDataReader read = sqlcom.ExecuteReader();
if (read.HasRows)
{
int k = 0;
while (read.Read())
{
dgv_Entry.Rows[k].Cells["ColumnName"].Value = read.GetString(0);
dgv_Entry.Rows[k].Cells["ColumnRate"].Value = read.GetString(1);
dgv_Entry.Rows[k].Cells["ColumnRQty"].Value = read.GetString(2);
dgv_Entry.Rows[k].Cells["ColumnTotal"].Value = Total;
k++;
}
}
sqlcon.Close();
And its MY Update Code..
if (btn_save.Text.Trim() == "&Update")
{
for (int no = 0; no <= dgv_Entry.Rows.Count - 1; no++)
{
if (dgv_Entry.Rows[no].Cells["ColumnName"].Value.ToString() == "" || dgv_Entry.Rows[no].Cells["ColumnName"].Value.ToString() == null)
{ break; }
else
{
VNo = txt_VocherNo.Text;
Name = dgv_Entry.Rows[no].Cells["ColumnName"].Value.ToString();
SRate = dgv_Entry.Rows[no].Cells["ColumnRate"].Value.ToString();
RQty = dgv_Entry.Rows[no].Cells["ColumnRQty"].Value.ToString();
Total = dgv_Entry.Rows[no].Cells["ColumnTotal"].Value.ToString();
Cmmd = "Update SALESENTRY Set Name = '" + Name + "',SRate ='" + Rate + "',RQty='" + Qty + "',Total='" + TotalAmount + "' Where Vno = '"+Vno+"'
DbCon.SetDataBase(Cmmd);
}
}
MessageBox.Show("Record Updated", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
Now How can i update Newly Added record Instead of Old
For Example.,I have Already 4 Records, now i want to Add one More Record using Update Button..How can i update?..
Please Suggest...