Hi
Into below code i am using it to check if the user had uploaded images before or not if yes then keep the old and update if the user has new files into fileuploads controls. But what i am looking for to update the code and delete UID and use AdsID column " column data type is: Int" which is passed by query string QADNUM. i tried to delete UID and use QADNUM instaed of UID but it dosent work and i tried to add QADNUM but i faced an error with code line: string[] images = GetImagess(Convert.ToString(QADNUM), QADNUM);
The error message with blow line under the above line : No overload for method 'GetImagess' takes 2 arguments
private string[] GetImagess(string UID)
{
string QADNUM = Request.QueryString["AID"];
SqlConnection EdPersInfoCon = new SqlConnection(ssc);
EdPersInfoCon.Open();
SqlCommand EdPersInfocmd = new SqlCommand();
string sqlstatment = @"select Img1,Img2,Img3,Img4,Img5 from ads Where AdsID=@qAdsID";
EdPersInfocmd.Connection = EdPersInfoCon;
EdPersInfocmd.CommandType = CommandType.Text;
EdPersInfocmd.CommandText = sqlstatment;
EdPersInfocmd.Parameters.AddWithValue("@qAdsID", QADNUM);
SqlDataReader reader = EdPersInfocmd.ExecuteReader();
string[] imagesUI = new string[5];
if (reader.Read())
{
for (int i = 0; i < 5; i++)
{
if (reader.GetValue(i) is DBNull)
{
imagesUI[i] = string.Empty;
}
else
{
imagesUI[i] = reader.GetString(i);
}
}
}
return imagesUI;
}
protected void EditAdsUpdateBtn_Click(object sender, EventArgs e)
{
HttpCookie cookie = Request.Cookies.Get("Location");
string Location = string.Empty;
string QADNUM = Request.QueryString["AID"];
var AdsNumL = EditAdsNumLbl.Text;
var UsrsNme = Session["UsrNme"];
string FileExtention = System.IO.Path.GetExtension(FileUpload1.FileName);
string FileExtention2 = System.IO.Path.GetExtension(FileUpload2.FileName);
string FileExtention3 = System.IO.Path.GetExtension(FileUpload3.FileName);
string FileExtention4 = System.IO.Path.GetExtension(FileUpload4.FileName);
string FileExtention5 = System.IO.Path.GetExtension(FileUpload5.FileName);
SqlConnection EdAdsCon = new SqlConnection(ssc);
SqlCommand cmd = new SqlCommand();
if (Session["UsrNme"] != null && cookie != null)
{
EdAdsCon.Open();
if (FileUpload1.HasFile || FileUpload2.HasFile || FileUpload3.HasFile || FileUpload4.HasFile || FileUpload5.HasFile)
{
var files = new[] { FileExtention, FileExtention2, FileExtention3, FileExtention4, FileExtention5 };
files = files.Where(s => !string.IsNullOrEmpty(s)).ToArray();
var extensions = new[] { ".jpg", ".png" };
if ((files.Except(extensions).Count()) <= 0)
{
string sqlstatment = @"Update ads SET Section=@Section, Category=@Category, State=@State,City=@City, AdsTit=@AdsTit, AdsDesc=@AdsDesc, AdsPrice=@AdsPrice, Wtags=@Wtags, Address=@Address, Maker=@Maker, Year=@Year,
Gear=@Gear, Condition=@Condition, RoomNo=@RoomNo, Status=@Status, Space=@Space, Shower=@Shower, Garage=@Garage, Img1=@Img1, Img2=@Img2,
Img3=@Img3, Img4=@Img4, Img5=@Img5, extlink=@extlink Where AdsID=@AdsID";
cmd.Connection = EdAdsCon;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlstatment;
cmd.Parameters.AddWithValue("@AdsID", QADNUM);
cmd.Parameters.AddWithValue("@Section", editadsSecdrdoads.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Category", EditAdsCatedrdoads.SelectedItem.Text);
cmd.Parameters.AddWithValue("@State", editstatedrdolst.SelectedItem.Text);
string imgnouser = "/images/general/nouser.jpg";
string[] images = GetImagess(Convert.ToString(UsrsNme), QADNUM);
if (FileUpload1.HasFile)
{
cmd.Parameters.AddWithValue("@Img1", FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/images/AdsImgs/" + FileUpload1.FileName));
}
else
{
if (string.IsNullOrEmpty(images[0]))
{
cmd.Parameters.AddWithValue("@Img1", imgnouser);
}
else
{
cmd.Parameters.AddWithValue("@Img1", images[0]);
}
}
if (FileUpload2.HasFile)
{
cmd.Parameters.AddWithValue("@Img2", FileUpload2.FileName);
FileUpload2.SaveAs(Server.MapPath("~/images/AdsImgs/" + FileUpload2.FileName));
}
else
{
if (string.IsNullOrEmpty(images[0]))
{
cmd.Parameters.AddWithValue("@Img2", imgnouser);
}
else
{
cmd.Parameters.AddWithValue("@Img2", images[1]);
}
}
....
}
else
{
WrngImgFormatLbl.Text = "Error: The file should have .png or .jpg format only";
WrngImgFormatLbl.ForeColor = System.Drawing.Color.Red;
return;
}
}
else
{
string sqlstatment = @"Update ads SET Section=@Section, Category=@Category, State=@State,
City=@City, AdsTit=@AdsTit, AdsDesc=@AdsDesc, AdsPrice=@AdsPrice, Wtags=@Wtags, Address=@Address, Maker=@Maker, Year=@Year,
Gear=@Gear, Condition=@Condition, RoomNo=@RoomNo, Status=@Status, Space=@Space, Shower=@Shower, Garage=@Garage, extlink=@extlink Where AdsID=@AdsID";
cmd = new SqlCommand(sqlstatment);
cmd.Connection = EdAdsCon;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlstatment;
cmd.Parameters.AddWithValue("@AdsID", QADNUM);
cmd.Parameters.AddWithValue("@Section", editadsSecdrdoads.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Category", EditAdsCatedrdoads.SelectedItem.Text);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ad.SelectCommand = cmd;
ad.Fill(ds);
}
int result = cmd.ExecuteNonQuery();
if (result > 0)
{
// Updated successfully;
}
}