多部分标识符QUOT; TextBox1.Text"不能在C#ASP.NET的约束? [英] The multi-part identifier "TextBox1.Text" could not be bound in C# ASP.NET?
问题描述
我做了一个培训项目的做法;我的处理程序已明令禁止paramaterization和面向安全编码就目前而言,在获得了基础知识的兴趣。话虽这么说,我有一个GridView在我的网页上的超链接字段,将用户带到一个页面,在这里他们可以在文本框编辑的行数据。该行的产品编号列中显示,因为它是自动增量和独一无二的。该值显示完美,所以我知道我的查询字符串是好的,但是当我尝试使用按钮事件更新,我得到,说
的错误信息的的多部分组成的标识符TextBox1.Text无法绑定。的
我所有的文本框。我的code如下。我在想什么?这是我第一次圈地,所以它很可能是基本的和明显的有经验的眼球。
使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用System.Data这;
使用System.Data.Sql;
使用System.Data.SqlClient的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls; 公共部分类ViewEdit:System.Web.UI.Page
{
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
字符串x =的Request.QueryString [产品编号];
字符串的connectionString = System.Configuration.ConfigurationManager.ConnectionStrings [MyConnectionString]的ConnectionString。
字符串editQuery =选择客户ID,的CustName,SicNaic,CustCity,CustAdd,CustState,CustZip,BroName,BroId,BroAdd,BroCity,BroState,BroZip,的EntityType,覆盖面广,CurrentCoverage,PRIMEX,保留,EFFECTIVEDATE,佣金,premium,最新评论来自ProductInstance WHERE产品编号=+ X; 使用(SqlConnection的editConn =新的SqlConnection(的connectionString))
{
editConn.Open(); 使用(的SqlCommand命令=新的SqlCommand(editQuery,editConn))
{ SqlDataReader的博士= Command.ExecuteReader却();
dr.Read();
TextBox1.Text = dr.GetInt32(0)的ToString();
TextBox2.Text = dr.GetString(1);
TextBox3.Text = dr.GetString(2);
TextBox4.Text = dr.GetString(3);
TextBox5.Text = dr.GetString(4);
TextBox6.Text = dr.GetString(5);
TextBox7.Text = dr.GetInt32(6)的ToString();
TextBox8.Text = dr.GetString(7);
TextBox9.Text = dr.GetInt32(8)的ToString();
TextBox10.Text = dr.GetString(9);
TextBox11.Text = dr.GetString(10);
TextBox12.Text = dr.GetString(11);
TextBox13.Text = dr.GetInt32(12)的ToString();
TextBox14.Text = dr.GetString(13);
TextBox15.Text = dr.GetInt32(14)的ToString();
TextBox16.Text = dr.GetInt32(15)的ToString();
TextBox17.Text = dr.GetInt32(16)的ToString();
TextBox18.Text = dr.GetInt32(17)的ToString();
TextBox19.Text = dr.GetDateTime(18)的ToString();
TextBox20.Text = dr.GetInt32(19)的ToString();
TextBox21.Text = dr.GetInt32(20)的ToString();
TextBox22.Text = dr.GetString(21); } }
}
保护无效的button1_Click(对象发件人,EventArgs的发送)
{
字符串x =的Request.QueryString [产品编号];
字符串的connectionString = System.Configuration.ConfigurationManager.ConnectionStrings [MyConnectionString]的ConnectionString。
字符串updateQuery =UPDATE ProductInstance SET CUSTID = TextBox1.Text,的CustName = TextBox2.Text,SicNaic = TextBox3.Text,CustCity = TextBox4.Text,CustAdd = TextBox5.Text,CustState = TextBox6.Text,CustZip = TextBox7.Text,BroName = TextBox8.Text,BroId = TextBox9.Text,BroAdd = TextBox10.Text,BroCity = TextBox11.Text,BroState = TextBox12.Text,BroZip = TextBox13.Text,的EntityType = TextBox14.Text,覆盖率= TextBox15.Text,CurrentCoverage = TextBox16 。文本,PRIMEX = TextBox17.Text,留着= TextBox18.Text,EFFECTIVEDATE = TextBox19.Text,佣金= TextBox20.Text,premium = TextBox21.Text,评论= TextBox22.Text WHERE产品编号=+ X;
使用(SqlConnection的updateConn =新的SqlConnection(的connectionString))
{
updateConn.Open();
{
使用(的SqlCommand命令=新的SqlCommand(updateQuery,updateConn))
{
command.ExecuteNonQuery();
}
}
}
}
}
您必须通过文本框<的
文本
属性的值/ code>控件来查询不是TextBox.Text作为一个字符串:
字符串updateQuery =UPDATE ProductInstance SET CUSTID =+ TextBox1.Text +的CustName ='+ TextBox2.Text +'......+ X;
注意
如果文本属性的值是一个字符串,你必须放置
对值的两侧像在上面的例子中
I'm doing a practice project for training; my handler has specifically forbidden paramaterization and security-oriented coding for now, in the interest of getting the basics down. That being said, I've got a gridview on my homepage with a hyperlink field that takes the user to a page where they can edit the row data in textboxes. The row is displayed by the "ProductId" column, as it is autoincremented and unique. The values display perfectly, so I know my query string is fine, but when I attempt to update using the button event, I get an error message that says
The multi-part identifier "TextBox1.Text" could not be bound.
for all of my textboxes. My code is below. What am I missing? This is my first rodeo, so it may very well be basic and obvious to an experienced eye.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ViewEdit : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string x = Request.QueryString["ProductId"];
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
string editQuery = "SELECT CustId, CustName, SicNaic, CustCity, CustAdd, CustState, CustZip, BroName, BroId, BroAdd, BroCity, BroState, BroZip, EntityType, Coverage, CurrentCoverage, PrimEx, Retention, EffectiveDate, Commission, Premium, Comments FROM ProductInstance WHERE ProductId =" + x;
using (SqlConnection editConn = new SqlConnection(connectionString))
{
editConn.Open();
using (SqlCommand command = new SqlCommand(editQuery, editConn))
{
SqlDataReader dr = command.ExecuteReader();
dr.Read();
TextBox1.Text = dr.GetInt32(0).ToString();
TextBox2.Text = dr.GetString(1);
TextBox3.Text = dr.GetString(2);
TextBox4.Text = dr.GetString(3);
TextBox5.Text = dr.GetString(4);
TextBox6.Text = dr.GetString(5);
TextBox7.Text = dr.GetInt32(6).ToString();
TextBox8.Text = dr.GetString(7);
TextBox9.Text = dr.GetInt32(8).ToString();
TextBox10.Text = dr.GetString(9);
TextBox11.Text = dr.GetString(10);
TextBox12.Text = dr.GetString(11);
TextBox13.Text = dr.GetInt32(12).ToString();
TextBox14.Text = dr.GetString(13);
TextBox15.Text = dr.GetInt32(14).ToString();
TextBox16.Text = dr.GetInt32(15).ToString();
TextBox17.Text = dr.GetInt32(16).ToString();
TextBox18.Text = dr.GetInt32(17).ToString();
TextBox19.Text = dr.GetDateTime(18).ToString();
TextBox20.Text = dr.GetInt32(19).ToString();
TextBox21.Text = dr.GetInt32(20).ToString();
TextBox22.Text = dr.GetString(21);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string x = Request.QueryString["ProductId"];
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
string updateQuery = "UPDATE ProductInstance SET CustId = TextBox1.Text, CustName = TextBox2.Text, SicNaic =TextBox3.Text, CustCity = TextBox4.Text, CustAdd = TextBox5.Text, CustState = TextBox6.Text, CustZip = TextBox7.Text, BroName = TextBox8.Text, BroId = TextBox9.Text, BroAdd = TextBox10.Text, BroCity = TextBox11.Text, BroState = TextBox12.Text, BroZip = TextBox13.Text, EntityType = TextBox14.Text, Coverage = TextBox15.Text, CurrentCoverage = TextBox16.Text, PrimEx = TextBox17.Text, Retention = TextBox18.Text, EffectiveDate = TextBox19.Text, Commission = TextBox20.Text, Premium = TextBox21.Text, Comments = TextBox22.Text WHERE ProductId =" + x;
using (SqlConnection updateConn = new SqlConnection(connectionString))
{
updateConn.Open();
{
using (SqlCommand command = new SqlCommand(updateQuery, updateConn))
{
command.ExecuteNonQuery();
}
}
}
}
}
You have to pass the value of the Text
property of the TextBox
controls to the query not the "TextBox.Text" as a string:
string updateQuery = "UPDATE ProductInstance SET CustId = " + TextBox1.Text + ", CustName = '" + TextBox2.Text + "', .... " + x;
NOTE:
If the value of the "Text" property was a string the you have to place a '
on the two sides of the value like in the example above.
这篇关于多部分标识符QUOT; TextBox1.Text&QUOT;不能在C#ASP.NET的约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!