0
在這裏,我寫的上傳圖片的編碼control.but獲得在SqlConnection的地方一些運行時error.error母豬 首先我
1.圖像名稱框 - 文本框
2.Image上傳控制 - ASP imageupload控件
3.上傳按鈕
的SqlConnection運行時錯誤
錯誤:從未同步的代碼塊調用對象同步方法。
代碼下面
public partial class ProfileDetails : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
//SqlConnection con = new SqlConnection("Data Source=CHATHU-LAPTOP;Initial Catalog=ProfilemgtDB;User ID=sa;Password=sa123");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void Upload_Click(object sender, EventArgs e)
{
string path = Server.MapPath("images/");
if (FileUpload1.HasFile)
{
string ext = Path.GetExtension(FileUpload1.FileName);
if (ext == ".jpg" || ext == ".png")
{
FileUpload1.SaveAs(path + FileUpload1.FileName);
string name = "~/images/" + FileUpload1.FileName;
string s = "Insert into Profile values('" + TextBox12.Text.Trim() + " '.'" + name + "')";
SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand(s, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Write("File Uploaded");
}
else
{
Response.Write("You can upload only JPG & PNG");
}
}
else {
Response.Write("Please Select File");
}
}
}
ERROR:對象同步方法是從代碼不同步塊調用。
哪一行是拋出該錯誤? –
SqlConnection con = new SqlConnection(connStr); –
可能與你的錯誤沒有任何關係,但是這個代碼是一個等待發生的災難。切勿使用字符串連接來創建sql值以傳遞INSERT,UPDATE,DELETE,SELECT等操作 – Steve