这种报错怎么处理呢?
问题描述:
以下为源代码,和报错图片
public partial class Default1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Box_Click(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
String connection="Data Source=.;Initial Catalog=no1;Integrated Security=SSPI";
SqlConnection con=new SqlConnection(connection);
con.Open();
string ConnectionString=ConfigurationManager.ConnectionStrings["othername"].ToString();
String sql2 ="insert into num(Table)(username,password)values('"+name+"','"+password+"')";
SqlCommand cmd=new SqlCommand(sql2,con);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("HelloWorld!你的手机号是" + telephone.Text);
Response.Write("HelloWorld!你的密码是"+password.Text );
Response.Write("你的用户名是" + name.Text);
Response.Write("你再次输入的密码是" + password1.Text);
}
protected void btn1_Click(object sender, EventArgs e)
{
String connection = "Data Source=.;Initial Catalog=no1;Integrated Security=SSPI";
SqlConnection con = new SqlConnection(connection);
con.Open();
string ConnectionString = ConfigurationManager.ConnectionStrings["othername"].ToString();
String sql1 = "select*from <Table> where id = 1";
SqlCommand cmd = new SqlCommand(sql1, con);
SqlDataReader read=cmd.ExecuteReader();
if(read.Read())
{
Response.Write(read["username"]+";"+read["password"]);
}
else{
Response.Write("查不到");
}
con.Close();
Response.Write("<script>alert('登录成功');</script>");
}
}
答
把SQL语句中的 <Table> 换成 [Table]
答
看报错像sql语句表名外面的尖括号