i am trying this way but i got error please Help me Friends....
public ActionResult Upload()
{
return View();
}
[HttpPost]
public ActionResult Upload(Image obj, HttpPostedFileBase aFile)
{
MySqlCommand cmd11 = new MySqlCommand("Select Count(*) from student", Con);
Con.Open();
int i = Convert.ToInt32(cmd11.ExecuteScalar()) + 1;
GenId = i + DateTime.Now.ToString("ss");
string filePath = Path.GetFileName(aFile.FileName);
string savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(aFile.FileName));
aFile.SaveAs(Server.MapPath("~/Content/Images/" + filePath));
MySqlCommand cmd = new MySqlCommand("Insert into student values(@Id,@Name,@EmailId,@MobileNo,@City,@Image", Con);
cmd.Parameters.AddWithValue("@Id", GenId);
cmd.Parameters.AddWithValue("@Name", obj.Name);
cmd.Parameters.AddWithValue("@EmailId", obj.EmailId);
cmd.Parameters.AddWithValue("@City", obj.City);
cmd.Parameters.AddWithValue("@MobileNo", obj.MobileNo);
cmd.Parameters.AddWithValue("@Image", savedFileName);
cmd.ExecuteNonQuery();
return View();
}
What I have tried:
public ActionResult Upload()
{
return View();
}
[HttpPost]
public ActionResult Upload(Image obj, HttpPostedFileBase aFile)
{
MySqlCommand cmd11 = new MySqlCommand("Select Count(*) from student", Con);
Con.Open();
int i = Convert.ToInt32(cmd11.ExecuteScalar()) + 1;
GenId = i + DateTime.Now.ToString("ss");
//HttpPostedFileBase aFile = Request.Files["Filedata"];
//int contentLength = aFile.ContentLength;
//byte[] bytePic = new byte[contentLength];
//aFile.InputStream.Read(bytePic, 0, contentLength);
string filePath = Path.GetFileName(aFile.FileName);
string savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(aFile.FileName));
aFile.SaveAs(Server.MapPath("~/Content/Images/" + filePath));
MySqlCommand cmd = new MySqlCommand("Insert into student values(@Id,@Name,@EmailId,@MobileNo,@City,@Image", Con);
cmd.Parameters.AddWithValue("@Id", GenId);
cmd.Parameters.AddWithValue("@Name", obj.Name);
cmd.Parameters.AddWithValue("@EmailId", obj.EmailId);
cmd.Parameters.AddWithValue("@City", obj.City);
cmd.Parameters.AddWithValue("@MobileNo", obj.MobileNo);
cmd.Parameters.AddWithValue("@Image", savedFileName);
cmd.ExecuteNonQuery();
return View();
}