连接数据库问题,新人求助
代码如下
public class biaodan : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
string yyy = context.Request["name"];
//int age = Convert.ToInt32(context.Request["age"]);
string ppp = context.Request["email"];
using (SqlConnection conn = new SqlConnection(
"Data Source=.;Initial Catalog=students;User ID=sa;Password=a6811065a "))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand()) //SqlCommand代表向数据库发出指令的这个个对象
{
cmd.CommandText = "Insert into Table_1(name,email) values(" + yyy + "," + ppp + ")";
cmd.ExecuteNonQuery();
}
}
}
当我向yyy和ppp传入值asd和asd时,总出现
求大神解答一下,怎么才能把yyy和ppp参数的值传入数据库。
------解决方案--------------------
cmd.CommandText = "Insert into Table_1(name,email) values('" + yyy + "','" + ppp + "')";
值上面加一个单引号试试