TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Micah David
NA
25
9k
Inserting and selecing record using userid not working
Oct 9 2015 7:13 PM
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";
}
}
}
}
}
}
}
}
Reply
Answers (
1
)
ERROR in creating a random number
Cannot apply indexing with [] to an expression of type "int"