急急啊~~~ 大家帮帮我~~
连接了数据库 为什么可以读 却不能添加 删除~
类:
//添加一个用户信息
public string AddUser(
string User_Name,
string User_Password,
string Work_Unit,
string Address,
string Tel,
Int32 Post,
string E_Mail
)
{
SqlConnection ApplicationCn=new SqlConnection(ConfigurationSettings.AppSettings["Censor"]);
SqlCommand ApplicationCmd=new SqlCommand("SP_AddUserMSG",ApplicationCn);
ApplicationCmd.CommandType=CommandType.StoredProcedure;
SqlParameter UserId=new SqlParameter("@User_Id",SqlDbType.NVarChar,10);
UserId.Direction=ParameterDirection.Output;
ApplicationCmd.Parameters.Add(UserId);
SqlParameter UserName=new SqlParameter("@User_Name",SqlDbType.NVarChar,10);
UserName.Value=User_Name;
ApplicationCmd.Parameters.Add(UserName);
SqlParameter UserPassword=new SqlParameter("@User_Password",SqlDbType.NVarChar,20);
UserPassword.Value=User_Password;
ApplicationCmd.Parameters.Add(UserPassword);
SqlParameter WorkUnit=new SqlParameter("@Work_Unit",SqlDbType.NVarChar,50);
WorkUnit.Value=Work_Unit;
ApplicationCmd.Parameters.Add(WorkUnit);
SqlParameter address=new SqlParameter("@Address",SqlDbType.NVarChar,50);
address.Value=Address;
ApplicationCmd.Parameters.Add(address);
SqlParameter tel=new SqlParameter("@Tel",SqlDbType.NVarChar,50);
tel.Value=Tel;
ApplicationCmd.Parameters.Add(tel);
SqlParameter post=new SqlParameter("@Post",SqlDbType.Int);
post.Value=Post;
ApplicationCmd.Parameters.Add(post);
SqlParameter EMail=new SqlParameter("@E_Mail",SqlDbType.NVarChar,20);
EMail.Value=E_Mail;
ApplicationCmd.Parameters.Add(EMail);
try
{
ApplicationCn.Open();
ApplicationCmd.ExecuteNonQuery();
ApplicationCn.Close();
return UserId.Value.ToString() ;
}
catch(System.Data.SqlClient.SqlException er)
{
return er.ToString();
}
}
后台代码:
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Department.Text="普通用户";
Popedom.Text="只读";
Censor.user Regist=new user();
Censor.userInfor RegistInfor=new userInfor();
string strStatus = String.Empty;
strStatus=Regist.AddUser(
username.Text,
pwd.Text,
work.Text,
adress.Text,
phone.Text,
Convert.ToInt32(post.Text),
email.Text
);
try
{
Int32.Parse(strStatus.ToString());
Response.Cookies["User_Name"].Value= username.Text;
Response.Cookies["Department"].Value=Department.Text;
Response.Cookies["User_ID"].Value=strStatus;
Response.Redirect("OK.aspx");
}
catch(FormatException er)
{
strStatus=er.ToString();
}
}
存储过程:
CREATE PROCEDURE SP_AddUserMSG
@User_Id varchar(15) output,
@User_Name Varchar(10), --用户名
@User_Password Varchar(20), --密码
@Work_Unit Varchar(50), --工作单位
@Address Varchar(50), --通讯地址
@Tel Varchar(20), --联系电话
@Post Int, --邮编
@E_Mail Varchar(20), --电子邮件
@Department Varchar(10), --所属部门(没有部门属普通用户)
@Popedom Varchar(20), --拥有权限(+R;+B;+E;+A;+D;+C[审批])
@Login_DateTime DateTime
as
INSERT INTO User_information
(User_Name,User_Password,Work_Unit,Address,Tel,Post,E_Mail,Department,Popedom,Login_DateTime)
VALUES (@User_Name,@User_Password,@Work_Unit,@Address,@Tel,@Post,@E_Mail,'普通用户','rb',getdate())
select @User_Id=scope_Identity()
GO