I searched on google but I couldn't get the right answer for my project..
I create a form in which i want to Insert,update and delete the records through the dataGridView..
My code is:-
public partial class orderListDetails : Form
{
Data_Conn DC;
string DelValue = string.Empty;
public orderListDetails()
{
InitializeComponent();
DC = new Data_Conn(Application.StartupPath);
}
private void orderListDetails_Load(object sender, EventArgs e)
{
DC.SelectSta("select proName as Name,proComp as Company,proQty as Qty,proUnit as Unit from orderList", "orderList");
dataGridView1.DataSource = DC.dataSet;
dataGridView1.DataMember = "orderList";
}
private void button5_Click(object sender, EventArgs e)
{
this.Dispose();
}
private void btnAddNew_Click(object sender, EventArgs e)
{
DC.CmdStatement("insert into orderList values('" + textBox1.Text + "','" + comboBox1.Text + "'," + Convert.ToInt32(textBox2.Text) + ",'" + comboBox2.Text + "')");
DC.SelectSta("select proName as Name,proComp as Company,proQty as Qty,proUnit as Unit from orderList", "orderList");
dataGridView1.DataSource = DC.dataSet;
dataGridView1.DataMember = "orderList";
dataGridView1.Refresh();
}
private void btnDelete_Click(object sender, EventArgs e)
{
try
{
DialogResult dr = MessageBox.Show("Do You want to delete the product details?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)
{
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
DC.CmdStatement("delete from orderList where proName='"+DelValue+"'");
DC.SelectSta("select proName as Name,proComp as Company,proQty as Qty,proUnit as Unit from orderList", "orderList");
dataGridView1.DataSource = DC.dataSet;
dataGridView1.DataMember = "orderList";
}
}
catch
{ }
}
private void btnUpdate_Click(object sender, EventArgs e)
{
DC.adpt.Update(DC.dataSet, "orderList");
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
DelValue = dataGridView1[0, e.RowIndex].Value.ToString();
}
}
when i click on Update button Its shows the error message
Update requires a valid UpdateCommand when passed DataRow collection with modified rows.
How to Update that record in database??
thanks in Advance....