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
Israel
699
1.3k
217.3k
Object reference not set to an instance of an object(???)
Dec 18 2016 11:26 AM
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 !";
}
Reply
Answers (
6
)
How to Increase Performance in my Database for 40000 Records
establishing connection using ado .net