关于数据库操作的小问题!!!
为什么下面的操作不能往表user里插入记录呢?连接数据库成功了。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string SqlStr = System.Configuration.ConfigurationManager.AppSettings["conStr"];
SqlConnection con = new SqlConnection(SqlStr);
con.Open();
if (con.State == System.Data.ConnectionState.Open)
{
Response.Write("SQL Server 数据库连接成功!");
con.Close();
return;
}
if (con.State == System.Data.ConnectionState.Closed)
{
Response.Write("失败");
}
string strSqlCom = "insert into user(username,userpassword) values('shabi','12312');";
SqlCommand sqlcom = new SqlCommand(strSqlCom, con);
sqlcom.ExecuteNonQuery();
}
}