我如何在C#中使用Page_Load()保存到数据库,我一直试图保存到MSSQL数据库中,但该列非常空白,而这些列中没有任何内容,因此我需要帮助ASP.NET的新手介绍
我的代码如下:
protected void Page_Load(object sender, EventArgs e)
{
string firstname = Request.QueryString["firstname"];
string lastname = Request.QueryString["lastname"];
string email = Request.QueryString["email"];
//Put user code to initialize the page here
Topaz.SigPlusNET sigObj = new Topaz.SigPlusNET();
sigObj.AutoKeyStart();
//use the same data to decrypt signature
sigObj.SetAutoKeyData(Request.Form["username"]);
sigObj.AutoKeyFinish();
sigObj.SetSigCompressionMode(1);
sigObj.SetEncryptionMode(2);
//Now, get sigstring from client
//Sigstring can be stored in a database if
//a biometric signature is desired rather than an image
//sigObj.SetSigString(Request.Form["hidden"]);
if (sigObj.NumberOfTabletPoints() > 0)
{
sigObj.SetImageFileFormat(0);
sigObj.SetImageXSize(500);
sigObj.SetImageYSize(150);
sigObj.SetImagePenWidth(8);
sigObj.SetJustifyX(5);
sigObj.SetJustifyY(5);
sigObj.SetJustifyMode(5);
System.Drawing.Image img = sigObj.GetSigImage();
base64ImageString = ImageToBase64(img, System.Drawing.Imaging.ImageFormat.Jpeg);
if (base64ImageString.Length > 3000)
{
using (SqlConnection con = new SqlConnection(constring))
{
con.Open();
string sql = "insert into SakalPicturecontrol (firstname,lastname,email,base64ImageString) Values (@firstname,@lastname,@email,@base64ImageString)";
try
{
using (SqlCommand cmd = new SqlCommand(sql, con))
{
cmd.Parameters.AddWithValue("@firstname", firstname);
cmd.Parameters.AddWithValue("@lastname", lastname);
cmd.Parameters.AddWithValue("@email", email);
cmd.Parameters.AddWithValue("@base64ImageString", base64ImageString);
cmd.ExecuteNonQuery();
Response.Write("Information has been saved Correctly..");
con.Close();
}
}
catch (Exception ex)
{
Response.Write("Error: " + ex.ToString());
}
}
}
}
else
{
//signature has not been returned successfully!
}
}