【问题标题】:Update command and SQLDataSource not functioning as expected更新命令和 SQLDataSource 未按预期运行
【发布时间】:2018-05-29 19:40:28
【问题描述】:

我使用服务器端的“select”命令填充我的<dx:ASPxTextBox>(DevExpress 控件),并使用以下代码(这是一个示例,大约有 20 个字段):CustomerID.Text = ds.Tables[0].Rows[0]["CustomerID"].ToString(); 按预期工作!

但是,我想使用 <asp:SqlDataSource> 控件更新我的表格,该控件与我在开始时用作控件参数时使用的相同文本框。当我为 .aspx 页面中的文本框赋值或像这样 exampletextbox.Text = "test"; 更新命令有效。我的结论是我无法成功更新我的表,因为文本框从服务器端的 sqlcommand 获取它们的值。有任何想法吗???我是不是做错了什么?

附加代码:

int customerUniqueID = 4;
        string constr = ConfigurationManager.ConnectionStrings["SQLConnection"].ToString(); // connection string
        SqlConnection con = new SqlConnection(constr);
        con.Open();
        SqlCommand com = new SqlCommand("SELECT * FROM [Customers] WHERE [UniqueID] = @UniqueID", con); // table name 
        com.Parameters.Add("@UniqueID", SqlDbType.Int);
        com.Parameters["@UniqueID"].Value = customerUniqueID;
        SqlDataAdapter da = new SqlDataAdapter(com);
        DataSet ds = new DataSet();
        da.Fill(ds, "Customers");

        CustomerID.Text = ds.Tables[0].Rows[0]["CustomerID"].ToString();
        CustomerName.Text = ds.Tables[0].Rows[0]["CustomerName"].ToString();
        Details.Text = ds.Tables[0].Rows[0]["Details"].ToString();

SqlDataSource:

UpdateCommand="UPDATE [Customers] SET [CustomerName] = @CustomerName, [Details] = @Details WHERE [CustomerID] = 4">

【问题讨论】:

  • 示例:

标签: c# asp.net sql-update devexpress sqldatasource


【解决方案1】:

发现问题...我不得不从 Page_Load 中删除“选择”代码... -.-

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 2014-12-11
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    • 1970-01-01
    • 2016-09-29
    相关资源
    最近更新 更多