After running this code which uploads image and text i got this error
Server Error in '/' Application.
Format of the initialization string does not conform to specification starting at index 0.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
Source Error:
Line 140: using (SqlConnection con = new SqlConnection())
Line 141: {
Line 142: con.ConnectionString = str;
Line 143: // Image extension.
Line 144: if (extension.ToLower() == ".jpg" || extension.ToLower() == ".png" || extension.ToLower() == ".gif" || extension.ToLower() == ".jpeg")
code
protected void btnsave_Click1(object sender, EventArgs e)
{
//int inserted = 0;
string username1 = string.Empty;
// string tendString = Textpost.Text.Trim();
// string strname = "";
string extension = "";
// string getADPOST = "";
string str = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
string filepath = hfFilePath.Value;
string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName());
string folderPath = Server.MapPath("~/path/"); //Please enter your folder Name here.
string ImagefolderPath = Server.MapPath("~/Images/"); //Please enter your folder Name here.
{
if (FileUpload1.HasFile)
{
str = FileUpload1.FileName.ToString();
extension = System.IO.Path.GetExtension(str);
using (SqlConnection con = new SqlConnection())
{
con.ConnectionString = str;
// Image extension.
if (extension.ToLower() == ".jpg" || extension.ToLower() == ".png" || extension.ToLower() == ".gif" || extension.ToLower() == ".jpeg")
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
//Change the query like below
//Make sure the column name matches the with the name provided in code as per your table
cmd.CommandText = "INSERT INTO Events (Title,Event_Category,ABACAEvent,Date,SheduleTime,Organizer,Venue,Banner) VALUES(@Title,@Event_Category,@ABACAEvent,@Date,@SheduleTime,@Organizer,@Venue,@Banner)";
// cmd.Parameters.AddWithValue("@UserName", HttpContext.Current.User.Identity.Name);
cmd.Parameters.AddWithValue("@Event_Category", ddrole.SelectedItem.Text.Trim());
cmd.Parameters.AddWithValue("@Title", txtitle.Text.Trim());
cmd.Parameters.AddWithValue("@ABACAEvent", txtevent.Text.Trim());
cmd.Parameters.AddWithValue("@Date", txtdate.Text.Trim());
cmd.Parameters.AddWithValue("@SheduleTime", txtime.Text.Trim());
cmd.Parameters.AddWithValue("@Organizer", txtorganizer.Text.Trim());
cmd.Parameters.AddWithValue("@Venue", txtvenue.Text.Trim());
cmd.Parameters.AddWithValue("@Banner", fileNameWithoutExtension + extension);
// cmd.CommandText = getADPOST;
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
// BindGrid();
string message = string.Empty;
{
// lblMessage2.Visible = true;
/// lblMessage2.Text = "Data Submitted Successfully";
}
ScriptManager.RegisterClientScriptBlock(btnsave, this.GetType(), "alert", "<script>alert('Data Submitted Successfully ... !!')</script>", false);
// lblMessage2.Text = "Inserted Quantity Is Higher than stock " + GetQuantity().ToString();
}
}
txtdate.Text = String.Empty;
txtevent.Text = String.Empty;
ddrole.SelectedItem.Text = String.Empty;
txtitle.Text = String.Empty;
}
// this.BindGrid();
}
}
}