ASP.NET如下代码为什么信息进不到数据库里?
我是一个新手,用的VS2008+SQL SEVER2005,从网上摘了一段代码改了改但是发现信息进不到数据库中,也没有错误提示,请大家帮我看看,谢谢啦cs文件:
private void Button1_Click(object sender, System.EventArgs e)
{
//get the acquired value
string userAccount = this.TextBox1.Text.Trim();
string userPassword = this.TextBox2.Text.Trim();
string userRealName = this.TextBox4.Text.Trim();
string userSex = this.ddlSex.SelectedItem.Value.Trim();
string userEmail = this.TextBox5.Text.Trim();
string useraddress = this.TextBox6.Text.Trim();
string userzipcode = this.TextBox7.Text.Trim();
string userphone = this.TextBox8.Text.Trim();
//operate the database
try
{
//config the database
string strConn=ConfigurationSettings.AppSettings["CakeData"];
SqlConnection sqlConn=new SqlConnection();
sqlConn.ConnectionString=strConn;
//create the command
SqlCommand cmd=new SqlCommand("InsertUser",sqlConn);
cmd.CommandType=CommandType.StoredProcedure;
//add parameters
cmd.Parameters.Add(new SqlParameter("@userID",userAccount));
cmd.Parameters.Add(new SqlParameter("@userName",userRealName));
cmd.Parameters.Add(new SqlParameter("@userSex",userSex));
cmd.Parameters.Add(new SqlParameter("@Password",userPassword));
cmd.Parameters.Add(new SqlParameter("@Email", userEmail));
cmd.Parameters.Add(new SqlParameter("@Address", useraddress));
cmd.Parameters.Add(new SqlParameter("@telephone", userphone));
cmd.Parameters.Add(new SqlParameter("@postcod", userzipcode));
//open the database
sqlConn.Open();
//save the affected result
int aff=cmd.ExecuteNonQuery();
//close the reader and the database
sqlConn.Close();
}
catch(Exception ex)
{
//Alert(ex.Message);
}
}
private void LB_SeeResult_Click(object sender, System.EventArgs e)
{
Server.Transfer("select_adapter.aspx");
}
}
追问:<connectionStrings>
<add name="CakeDataConnectionString" connectionString="Data Source=MAXFONG\SQLEXPRESS;Initial Catalog=CakeData;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CakeData.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>是这个么?