1
Answer

Inserting and selecing record using userid not working

Micah David

Micah David

9y
649
1
protected void btnPost_Click(object sender, EventArgs e)
{
if (txtTitle.Text == "")
{
ScriptManager.RegisterClientScriptBlock(btnPost, this.GetType(), "alert", "<script>alert('Insert Location ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (txtName.Text == "")
{
ScriptManager.RegisterClientScriptBlock(btnPost, this.GetType(), "alert", "<script>alert('Insert Department Name ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (txtDate_Posted.Text == "")
{
ScriptManager.RegisterClientScriptBlock(btnPost, this.GetType(), "alert", "<script>alert('Insert Date... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (txtcontent.Text == "")
{
ScriptManager.RegisterClientScriptBlock(btnPost, this.GetType(), "alert", "<script>alert('Insert Category ... !!')</script>", false);
}
else
{
lblMessage2.Text = "";
if (!object.Equals(Session["UserId"], null))
{
if (FileUpload1.PostedFile != null)
{
string myMap = MapPath("~/").ToLower();
Random r = new Random();
int next = r.Next();
string ImageName = FileUpload1.PostedFile.FileName;
// ToSaveImageName = DateTime.Now.ToString("yyyy-MM-ddTmm:hh:ss");
//ToSaveImageName.Replace('-', '1');
//ToSaveImageName.Replace(':', '2');
//Directory.CreateDirectory(myMap + ToSaveImageName);
sImageFileExtension = ImageName.Substring(ImageName.LastIndexOf(".")).ToLower();
if (sImageFileExtension == ".gif" || sImageFileExtension == ".png" || sImageFileExtension == ".jpg" || sImageFileExtension == ".jpeg" || sImageFileExtension == ".bmp")
{
string ImageSaveURL = myMap + "UserImage/" + next + sImageFileExtension;
try
{
FileUpload1.PostedFile.SaveAs(ImageSaveURL);
//Added connectionString to webconfig file and calling here
// string str = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
// string post = "Insert INTO ADTABLE (MyId,Title,Name,HashTag,ADContent,ImageName) VALUES('" + Session["UserId"].ToString() + "','" + Request.QueryString["Id"].ToString() + "','" + txtTitle.Text + "', '" + txtName.Text + "', '" + txtHashTag.Text + "', '" + txtcontent.Text + "', '" + sImageFileExtension + "')";
dbClass.MyDataBaseToInsert("InsertPaidTable", txtTitle.Text, txtName.Text, txtHashTag.Text, txtcontent.Text, sImageFileExtension);
// string post = "Insert INTO ADTABLE (MyId,Title,Name,HashTag,ADContent,ImageName) VALUES('" + Session["UserId"].ToString() + "','" + Request.QueryString["Id"].ToString() + "','" + txtTitle.Text + "', '" + txtName.Text + "', '" + txtHashTag.Text + "', '" + txtcontent.Text + "', '" + sImageFileExtension + "')";
// dbClass.ConnectDataBaseToInsert(post);
Response.Redirect("~/Pages/UserProfile.aspx?Id=" + Request.QueryString["Id"].ToString());
{
// Response.Redirect("~/Account/Login.aspx");
}
}
catch (Exception ex)
{
}
}
else
{
}
}
else
{
ToSaveImageName = "No";
sImageFileExtension = "Image";
}
}
}
}
}
}
}
}

Answers (1)
Next Recommended Forum