SqlConnection con = new SqlConnection("server=.;database=master;uid=sa;pwd=");
con.Open();
SqlCommand userCmd = new SqlCommand("InsertUser", con);
userCmd.CommandType = CommandType.StoredProcedure;
SqlParameter spName = new SqlParameter("@userName", SqlDbType.NVarChar, 20);
cmd.Parameters.Add(spName);
spName.Value = this.txtName.Text;
SqlParmeter spPwd = new SqlParmameter("@userPwd",SqlDbType.NvarChar,20);
cmd.Parmameters.Add(spPwd);
spPwd.Value = this.txtUserPwd.Text;
int iReturn = 0;
try
{
iReturn = userCmd.ExecuteNonQuery();
}
catch(Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
return iReturn;
提示:执行的时候最好是try Catch下!^_^