Hi!
I am testing my code. Curiously, later after running I have this message (Object reference not set to an instance of an object) pointed on this line here:
string connStr = ConfigurationManager.AppSettings["Data Source=LUNASOFTRESEARC\\SQLEXPRESS;Initial Catalog=RentMyWrox;Integrated Security=True"].ToString();
I need your help please. Thank you!
string fileName = FileUpload1.PostedFile.FileName;
int fileLength = FileUpload1.PostedFile.ContentLength;
byte[] imageBytes = new byte[fileLength];
FileUpload1.PostedFile.InputStream.Read(imageBytes, 0, fileLength);
string connStr = ConfigurationManager.AppSettings["Data Source=LUNASOFTRESEARC\\SQLEXPRESS;Initial Catalog=RentMyWrox;Integrated Security=True"].ToString(); //Here where is the bugg
using (SqlConnection conn = new SqlConnection(connStr))
{
string sql = "INSERT INTO ImageUpload (PictureName, PictureFile) VALUES (@pictureName, @pictureFile)";
SqlParameter[] prms = new SqlParameter[2];
prms[0] = new SqlParameter("@pictureName", SqlDbType.VarChar, 50);
prms[0].Value = fileName;
prms[1] = new SqlParameter("@pictureFile", SqlDbType.Image);
prms[1].Value = imageBytes;
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddRange(prms);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
lblMessage.Text = "Picture uploaded successsfully !";
}
Manas MohapatraPosted Dec 19, 2016, 1:40 AM
Mangesh GPosted Dec 18, 2016, 5:07 PM
IsraelPosted Dec 18, 2016, 2:52 PM
Amit Kumar SinghPosted Dec 18, 2016, 2:16 PM
{
string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
using(SqlConnection connection = new SqlConnection(connectionInfo))
{
connection.Open();
// perform work with connection
}
}
Manas MohapatraPosted Dec 18, 2016, 1:56 PM
Rajeesh MenothPosted Dec 18, 2016, 1:15 PM