学了两天ASP.net 的问题

来源:百度知道 编辑:UC知道 时间:2024/05/12 23:27:23
自学了两天ASP.net ,下面代码能生成 网页,但是怎么按也没反应,希望高手帮我改一下。。。最好能解释下,谢谢。。。
namespace test2{
/// <summary>
/// test 的摘要说明。
///
/// </summary>
public class test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Label Label3;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeCompone

string strSQL=("SELECT n_id FROM users WHERE n_id='"+TextBox1.Text+"'");
SqlCommand cmd= new SqlCommand("strSQL" , objConnection);

改为:
SqlCommand cmd= new SqlCommand("SELECT n_id FROM users WHERE n_id='"+TextBox1.Text+"'" , objConnection);

注意:要看你的n_id是什么类型的,是varchar类型的话就用上面的代码
如果是int类型的话就用一下代码:
SqlCommand cmd= new SqlCommand("SELECT n_id FROM users WHERE n_id="+TextBox1.Text+"" , objConnection);

int类型是没有单引号的,你写的代码在n_id字段都有单引号

string strSQL=("SELECT n_id FROM users WHERE n_id='"+TextBox1.Text+"'");
SqlCommand cmd= new SqlCommand("strSQL" , objConnection);

这里的"strSQL" 不要加"" 这里要的是参数

还有就是 楼上的 作为条件查询 INT类型的加上''效果是一样
不信你可以自己去查询分析器里去试试
真不知道你是咋学的