首页 > 解决方案 > 更新命令和 SQLDataSource 未按预期运行

问题描述

我使用以下代码从服务器端使用“select”命令填充我的<dx:ASPxTextBox>(DevExpress Control)(这是一个示例,大约有 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.netsql-updatedevexpresssqldatasource

解决方案


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


推荐阅读