c# - 更新命令和 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">
解决方案
发现问题......我不得不从 Page_Load 中删除“选择”代码...... -.-
推荐阅读
- javascript - 尝试添加照片而不是颜色
- node.js - Strapi 管理面板用户权限初始化 404
- node.js - NodeJS 加密模块不适用于 http 模块
- flutter - 如何在 Flutter 中创建工作侧边栏
- kubernetes - Kubernetes 集群:如何确定哪些节点是主节点
- python - cx_Oracle 连接失败,出现“DPI-1047:找不到 64 位 Oracle 客户端库”
- c# - System.IO.FileNotFoundException:'在 xamarin 表单中找不到文件“/mytextfile.txt”'
- python - Scipy 和请求的 ImportErrors
- r - 输入 `var` 必须是向量,而不是 `formula` 对象。[案例_何时; 变异问题]
- javascript - 如何从 ExpressJS 流式传输 JSON 对象?