超网格更新 [英] ultra grid updating

查看:84
本文介绍了超网格更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我吗?
我使用以下代码插入一个表并通过将name设置为另一个表上的primarykey来更新字段.在调试时,如果我选择一个名称来显示要在超网格中显示的内容,则会显示类似...的异常...``对于不返回任何键列信息的SelectCommand,不支持UpdateCommand的动态SQL生成''. ...我的代码在下面标记:

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();
    //DataTable dts = new DataTable();
    connect c = new connect();
    SqlConnection s1 = c.con1();
    //DataSet ds = new DataSet("electrical");
    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);//auto generate the UpdateCommand,InsertCommand and DeleteCommand
    dts.Clear();
    //dt.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;
    ////
    //DataSet dst = new DataSet();
    //da1.InsertCommand = cmbuilder.GetInsertCommand();
    ////da1.UpdateCommand = cmbuilder.GetUpdateCommand();
    //da1.Update(dst.Tables[0].Select(null, null, DataViewRowState.CurrentRows));

    ////DataSet ds2 = new DataSet("electricals");
    da1.Update(dts);
    //da1.Update(dst.Tables["credit"].Select(null, null, DataViewRowState.CurrentRows));//, "credit");


    dt.Columns.Remove(column1);
    dt.Columns.Remove(column14);
    dt.Columns.Remove(column2);
    dt.Columns.Remove(column3);
    dt.Columns.Remove(column4);
    MessageBox.Show("Updated");
    // dt.Clear();
    // dts.Clear();

    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

推荐答案

在我看来,您的表缺少主键.与插入不同,您需要更新主键.

祝你好运
Seems to me that your table is missing a primary key. Unlike Insert it you update you need a primary key.

Good luck


这篇关于超网格更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆