源程序:
if(Page.IsValid)
{
string strconn= ConfigurationSettings.AppSettings["dsn"];
SqlConnection cn;
cn=new SqlConnection(strconn);
SqlConnection cn1=new SqlConnection(strconn);
SqlCommand cm=new SqlCommand("insert_personnel_information",cn);
cm.CommandType=CommandType.StoredProcedure;
try
{
cm.Parameters.Add(new SqlParameter("@number",SqlDbType.VarChar,50));
cm.Parameters["@number"].Value=Tbx_addnum.Text;
cm.Parameters.Add(new SqlParameter("@name",SqlDbType.VarChar,50));
cm.Parameters["@name"].Value=Tbx_addname.Text;
cm.Parameters.Add(new SqlParameter("@birth",SqlDbType.DateTime,8));
cm.Parameters["@birth"].Value=Tbx_birth.Text;
cm.Parameters.Add(new SqlParameter("@marriage",SqlDbType.Char,10));
if(Rbn_married.Checked)
{
cm.Parameters["@marriage"].Value="是";
}
else if(Rbn_unmarried.Checked)
{
cm.Parameters["@marriage"].Value="否";
}
cm.Parameters.Add(new SqlParameter("@worktime",SqlDbType.Char,10));
cm.Parameters["@worktime"].Value=Tbx_addworktime.Text;
cm.Parameters.Add(new SqlParameter("@intime",SqlDbType.DateTime,8));
cm.Parameters["@intime"].Value=Tbx_intime.Text;
cm.Parameters.Add(new SqlParameter("@department",SqlDbType.VarChar,50));
cm.Parameters["@department"].Value=Tbx_department.Text;
cm.Parameters.Add(new SqlParameter("@position",SqlDbType.VarChar,50));
cm.Parameters["@position"].Value=Tbx_addposition.Text;
cm.Parameters.Add(new SqlParameter("@phone",SqlDbType.Char,10));
cm.Parameters["@phone"].Value=Tbx_addphone.Text;
cm.Connection.Open();
string strsl="insert into users(UID,UPassword,UPower)values(@number,@password,0)";
SqlCommand cm1=new SqlCommand(strsl,cn1);
cm1.Parameters.Add(new SqlParameter("@number",SqlDbType.VarChar,50));
cm1.Parameters["@number"].Value=Tbx_addnum.Text;
cm1.Parameters.Add(new SqlParameter("@password",SqlDbType.VarChar,50));
cm1.Parameters["@password"].Value=Tbx_password.Text;
cm1.Connection.Open();
//对用户信息表和员工信息表进行添加
cm.ExecuteNonQuery();
cm1.ExecuteNonQuery();
Lbl_addmessage.Text="注册成功";
cm1.Connection.Close();
cm.Connection.Close();
}
catch
{
Lbl_addmessage.Text="注册失败,请检查输入!";
Lbl_addmessage.Style["color"]="red";
}
}
源程序已经调试过但是就是向数据库中添加不了数据,清各位高手指教一二!不胜感谢!!!!在线等待!