ASP.NET - Qry Error - Asked By Jahir on 02-Mar-12 12:19 AM


i have error in this qry ?

if (System.IO.Path.GetExtension(FileUpload1.FileName) == ".jpg" || System.IO.Path.GetExtension(FileUpload1.FileName) == ".png" || System.IO.Path.GetExtension(FileUpload1.FileName) == ".gif"|| System.IO.Path.GetExtension(FileUpload1.FileName) == ".bmp"|| System.IO.Path.GetExtension(FileUpload1.FileName) == ".jpeg")

{

string file = Path.GetFileName(FileUpload1.PostedFile.FileName);

FileUpload1.SaveAs(Server.MapPath(

"D:/image/img/" + file));

cmd= new SqlCommand("insert into tbl_fileupload(title,path)values('"+TextBox1.Text+"','"+D:/image/img/.file+"')",con); //error invalid expression ')',  and  invalid expression ',',  and ;expected

cmd.ExecuteNonQuery();

ShowAlertMessage(

"Inserted Successfully");

bindgrid();

}

else

{

ShowAlertMessage("No File Uploaded");

}

Web Star replied to Jahir on 02-Mar-12 12:26 AM
yes you can see there are error and showing message as nvalid expression  actually you can't get file from path dierctly that's why i give you link to sample for using upload control an you need to save selected file on server than you will insert the path into the table.
plz don't start new thread for same query
Reena Jain replied to Jahir on 02-Mar-12 12:40 AM
hi,

For that you can use FileName Property of FileUploadControl.
protected void Button3_Click(object sender, EventArgs e)
 
{
string filename = FileUpload1.PostedFile.FileName;
string insertQuery = "insert into tablename emp values(' " + strEmpId + " ','" + filename  + "') ";
SqlConnection cn = new SqlConnection("CONNECTION STRING");
cn.Open();
SqlCommand cmd = new SqlCommand(deleteQuery, cn);
cmd.ExecuteNonQuery();
cn.Close();
 
 }
Chintan Vaghela replied to Jahir on 02-Mar-12 01:06 AM

Hello,

Try as following way

          string file = Path.GetFileName(FileUpload1.PostedFile.FileName);

          string path = "D:/image/img/" + file;

          FileUpload1.SaveAs(Server.MapPath(path));

          new SqlCommand("insert into tbl_fileupload(title,path)values(" + TextBox1.Text + "," + path + ")", con);

Hope this is helpful !

Thanks

 

 

 

 

 

Jahir replied to Chintan Vaghela on 02-Mar-12 01:23 AM
thank you today i will be on leave see tommorr,,, i am suffering from  fever
Chintan Vaghela replied to Jahir on 02-Mar-12 04:33 AM
Get well soon
Jahir replied to Chintan Vaghela on 02-Mar-12 04:46 AM
thank you so much friend, ok i want sql server2005 software download link, and tel me the procedure to install, and i have installed visual studio 2010 in my laptop how to add ajax in that ? i dont know anything about that tel me pls how to install that ajax, and where will i get that ajax softare download link ?
Jahir replied to Chintan Vaghela on 02-Mar-12 11:21 PM
Error 1 'System.IO.Path' is a 'type' but is used like a 'variable' D:\image\Default2.aspx.cs 70 104 D:\image\
i have error like this in this coding when executing...

if (System.IO.Path.GetExtension(FileUpload1.FileName) == ".jpg" || System.IO.Path.GetExtension(FileUpload1.FileName) == ".png" || System.IO.Path.GetExtension(FileUpload1.FileName) == ".gif"|| System.IO.Path.GetExtension(FileUpload1.FileName) == ".bmp"|| System.IO.Path.GetExtension(FileUpload1.FileName) == ".jpeg")

{

string file = Path.GetFileName(FileUpload1.PostedFile.FileName);

string path = "D:/image/img/" + file;

FileUpload1.SaveAs(Server.MapPath(path));

cmd= new SqlCommand("insert into tbl_fileupload(title,path)values('"+TextBox1.Text+"','"+Path+"')",con); //error

cmd.ExecuteNonQuery();

ShowAlertMessage(

"Inserted Successfully");

bindgrid();

}

else

{

ShowAlertMessage("No File Uploaded");

}

Chintan Vaghela replied to Jahir on 02-Mar-12 11:55 PM
Hello

Change Path to path in your insert query