Can anybody help me?
I used the following code for inserting to one table and to update the field by setting name as primarykey on-another table . On debuging if i select a name to display the content to ultra grid it show the exception like ... 'Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information'. ... "my code is marked below:
private void button2_Click(object sender, EventArgs e)
{
DataTable dts = new DataTable();
int u;
u = dt.DefaultView.Table.Rows.Count;
SqlDataAdapter da1 = new SqlDataAdapter();
connect c = new connect();
SqlConnection s1 = c.con1();
SqlCommand cm = new SqlCommand("select BILLNO,NAME,CONTRACTOR,SITE, COMPANY,PRODUCT,PRODUCTTYPE,QTY,MRP,RATE,AMT,[DISCOUNT%],TOTAL ,DATE from credit", con);
da1.SelectCommand = cm;
SqlCommandBuilder cmbuilder = new SqlCommandBuilder(da1);
dts.Clear();
da1.Fill(dts);
if (comboBox5.Text == "")
{
comboBox5.Text = "";
}
if (comboBox4.Text == "")
{
comboBox4.Text = "";
}
if (comboBox6.Text == "")
{
comboBox6.Text = "";
}
DataRow row = null;
DataColumn column1 = new DataColumn("BILLNO", typeof(int));
dt.Columns.Add(column1);
DataColumn column14 = new DataColumn("DATE", typeof(DateTime));
dt.Columns.Add(column14);
DataColumn column2 = new DataColumn("NAME", typeof(string));
dt.Columns.Add(column2);
DataColumn column3 = new DataColumn("CONTRACTOR", typeof(string));
dt.Columns.Add(column3);
DataColumn column4 = new DataColumn("SITE", typeof(string));
dt.Columns.Add(column4);
for (int i = 1; i <= u; i++)
{
row = dt.Rows[i - 1];
row["BILLNO"] = int.Parse(textBox1.Text);
row["DATE"] = dateTimePicker1.Value.ToShortDateString();
row["NAME"] = comboBox5.Text;
row["CONTRACTOR"] = comboBox4.Text;
row["SITE"] = comboBox6.Text;
}
this.ultraGrid1.BindingContext[dts].EndCurrentEdit();
this.ultraGrid1.PerformAction(UltraGridAction.DeleteRows);
dts = dt;
da1.Update(dts);
dt.Columns.Remove(column1);
dt.Columns.Remove(column14);
dt.Columns.Remove(column2);
dt.Columns.Remove(column3);
dt.Columns.Remove(column4);
MessageBox.Show("Updated");
this.BeginInvoke(new MethodInvoker(this.SetActiveCell));
try
{
if (comboBox5.Text == "")
{
comboBox5.Text = "";
}
if (comboBox4.Text == "")
{
comboBox4.Text = "";
}
if (comboBox6.Text == "")
{
comboBox6.Text = "";
}
connect c1 = new connect();
c1.idu("insert into creditcustomer values(" + textBox1.Text + ",'" + comboBox5.Text + "','" + dateTimePicker1.Value.ToShortDateString() + "','" + comboBox4.Text + "','" + comboBox6.Text + "'," + textBox7.Text + "," + textBox12.Text + "," + textBox2.Text + "," + textBox12.Text + ")");
MessageBox.Show("inserted");
connect cc4 = new connect();
DataTable dtt4 = cc4.select(" select COMPANY,PRODUCT,RATE,QTY,AMT ,TOTAL from credit where BILLNO=" + textBox1.Text + "");
dgv.DataSource = dtt4;
}
catch (Exception)
{
connect cc = new connect();
cc.idu(" update creditcustomer set BILLNO=" + textBox1.Text + ",DATE='" + dateTimePicker1.Value.ToShortDateString() + "',TOTALAMOUNT=" + textBox7.Text + ",CURRENTBALANCE= " + textBox12.Text + ", PAID = " + ptxt17.Text + ", BALANCE=" + textBox12.Text + " where NAME='" + comboBox5.Text + "'");
MessageBox.Show("ITEMS ADDED");
connect c4 = new connect();
DataTable dt4 = c4.select(" select CONTRACTOR,SITE,CONVERT (VARCHAR(10),DATE,103) AS DATE, TOTALAMOUNT from creditcustomer where BILLNO=" + textBox1.Text + "");
dgv.DataSource = dt4;
}
}
How can I avoid the error? Please help me.
Thanks in advance