下面的代码工作得很好,但是当我创建新用户并检查MS Sql时,我可以找到我输入但没有图像名称的新用户,也无法将图像存储在项目文件中,请任何帮助
public partial class Registration:System.Web.UI.Page {
string sc = ConfigurationManager.ConnectionStrings["BeravaConnectionString"].ConnectionString.ToString();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(sc);
cn.Open();
SqlCommand cmd = new SqlCommand();
string sqlstatment= "INSERT INTO [dbo].[UserInfo]"+
" ([UID]"+
" ,[FN] "+
" ,[LN]" +
",[Password] "+
" ,[RePass] "+
" ,[Email] "+
" ,[CountID] "+
" ,[State] "+
" ,[City] "+
" , [Post] " +
" ,[Img]) values (@UID,@FN,@LN,@Password,@RePass,@Email,@CountID,@State,@City,@Post,@Img)";
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlstatment;
cmd.Connection = cn;
cmd.ExecuteNonQuery();
cmd.Parameters.AddWithValue("@UID", UsrNme.Text);
cmd.Parameters.AddWithValue("@FN", fnbox.Text);
cmd.Parameters.AddWithValue("@LN", lnamebox.Text);
cmd.Parameters.AddWithValue("@Password", passtxtbx1.Text);
cmd.Parameters.AddWithValue("@RePass", passtxtbx2.Text);
cmd.Parameters.AddWithValue("@Email", emailbox.Text);
cmd.Parameters.AddWithValue("@CountID", DDLCOUNTRY.Text);
cmd.Parameters.AddWithValue("@State", DDLSTATE.Text);
cmd.Parameters.AddWithValue("@City", citytxtbox.Text);
cmd.Parameters.AddWithValue("@Post",postbox.Text);
cmd.Parameters.AddWithValue("@Img", FileUpload1.FileName);
if (FileUpload1.HasFile && FileUpload1.PostedFile.ContentLength > 0)
{
FileUpload1.SaveAs(Server.MapPath("~/images/users/" + FileUpload1.FileName));
}
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ad.SelectCommand = cmd;
ad.Fill(ds);
Response.Redirect("User panel.aspx");
}
}