sqlselectstring="select Test from table where 字段ID='"+...+"'";//查询语句...... ... sqldataReader myreader=cmd.extuceReader() textbox.text=myreader["Test"].tostring();
using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { aa(); } } protected void aa() { string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["SqlConn"]); SqlConnection myconn = new SqlConnection(settings); myconn.Open(); SqlCommand cm = new SqlCommand("select TypeName from Departype where id=' + this.TextBox2.Text + ", myconn); SqlDataReader aa = cm.ExecuteReader(); aa.Read(); TextBox1.Text = aa["TypeName"].ToString(); myconn.Close(); } protected void Button1_Click1(object sender, EventArgs e) { string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["SqlConn"]); SqlConnection myconn = new SqlConnection(settings); myconn.Open(); SqlCommand cm = new SqlCommand("update Departype set TypeName='" + this.TextBox1.Text + "' where TypeNumber=' + this.TextBox2.Text + ", myconn); cm.ExecuteNonQuery(); myconn.Close(); Response.Redirect(Request.Url.ToString()); } }麻烦看看这段错哪了,怎么报错
应该是这样 SqlCommand cm = new SqlCommand("select TypeName from Departype where id='" + this.TextBox2.Text + "'", myconn); 和 SqlCommand cm = new SqlCommand("update Departype set TypeName='" + this.TextBox1.Text + "' where TypeNumber='" + this.TextBox2.Text + "'", myconn);
...
sqldataReader myreader=cmd.extuceReader()
textbox.text=myreader["Test"].tostring();
- -!!!你的问题不是这样的吧??
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
aa();
}
} protected void aa()
{
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["SqlConn"]);
SqlConnection myconn = new SqlConnection(settings);
myconn.Open(); SqlCommand cm = new SqlCommand("select TypeName from Departype where id=' + this.TextBox2.Text + ", myconn);
SqlDataReader aa = cm.ExecuteReader();
aa.Read();
TextBox1.Text = aa["TypeName"].ToString();
myconn.Close();
}
protected void Button1_Click1(object sender, EventArgs e)
{
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["SqlConn"]);
SqlConnection myconn = new SqlConnection(settings);
myconn.Open();
SqlCommand cm = new SqlCommand("update Departype set TypeName='" + this.TextBox1.Text + "' where TypeNumber=' + this.TextBox2.Text + ", myconn);
cm.ExecuteNonQuery();
myconn.Close();
Response.Redirect(Request.Url.ToString());
}
}麻烦看看这段错哪了,怎么报错
少了个单引号。 this.TextBox2.Text+"'",myconn);
SqlCommand cm = new SqlCommand("select TypeName from Departype where id='" + this.TextBox2.Text + "'", myconn);
和
SqlCommand cm = new SqlCommand("update Departype set TypeName='" + this.TextBox1.Text + "' where TypeNumber='" + this.TextBox2.Text + "'", myconn);
while(aa.read())
{
TextBox1.Text = aa["TypeName"].ToString();
}
不过,我经常把字段填到tag中,然后循环绑定
就是在TextBox2中输入查询条件,然后Button1查询,结果在TextBox1中显示出来
希望谁能给出完整的代码,非常感谢
谁能说说:
我想在TextBox2中输入查询条件,然后在TextBox1中显示,应该怎么写?
就是在TextBox2中输入查询条件,然后Button1查询,结果在TextBox1中显示出来
希望谁能给出完整的代码,非常感谢