我正在尝试将数据和图像插入表格但不能
我也没有收到任何错误,那么可能会出现什么问题呢?
我哪里错了?
当我开始调试时,字符串正在取每个值
这是我的代码
protected void btnsubmit_Click(object sender, EventArgs e)
{
string un = TextBox1.Text;
string pass = TextBox5.Text;
string add = TextBox2.Text;
string mob = TextBox3.Text;
string sal = TextBox4.Text;
string path = Server.MapPath("~/image/");
if (FileUpload1.HasFile)
{
string file = FileUpload1.FileName;
string ext = Path.GetExtension(file);
if (ext == ".jpg" || ext == ".jpeg" || ext == ".png")
{
string concat = path + file;
FileUpload1.SaveAs(concat);
SqlConnection con = new SqlConnection("connectionstring");
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into exmpl values(@Username,@Address,@Mobno,@Salary,@Image,@Password)";
cmd.Parameters.Add("@Username", SqlDbType.NVarChar).Value = un;
cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = add;
cmd.Parameters.Add("@Mobno", SqlDbType.NVarChar).Value = mob;
cmd.Parameters.Add("@Salary", SqlDbType.NVarChar).Value = sal;
cmd.Parameters.AddWithValue("@Image", "~/image/" + file);
cmd.Parameters.Add("@Password", SqlDbType.NVarChar).Value = pass;
cmd.ExecuteNonQuery();
con.Close();
Label1.Text = "registered..login now";
}
else
{
Label1.Text = "invalid file";
}
}
else
{
Label1.Text = "select file";
}