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
Viswa Kousika
NA
12
1.5k
object reference is not set to an instance of an object
Dec 9 2016 3:33 AM
hi, good afternoon
i am getting null reference error "(object reference is not set to an instance of an object)"...
this is my code..........
try
{
string ConStr = ConfigurationManager.ConnectionStrings["MYDB"].ToString();
SqlConnection con = new SqlConnection(ConStr);
con.Open();
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
string sql = "INSERT INTO [MyAssignment].[dbo].[Tblcustomer]([custname],[custtype],[address],[phonenumber],[emailid],[active])"
+ "VALUES('" + dataGridView1.Rows[i].Cells["Column2"].Value.ToString() + "','"
+ dataGridView1.Rows[i].Cells["Column3"].Value.ToString() + "','"
+ dataGridView1.Rows[i].Cells["Column4"].Value.ToString() + "',"
+ Convert.ToInt32(dataGridView1.Rows[i].Cells["Column5"].Value.ToString()) + ",'"
+ dataGridView1.Rows[i].Cells["Column6"].Value.ToString() + "','"
+ dataGridView1.Rows[i].Cells["Column7"].Value.ToString() + "')";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
}
MessageBox.Show("Inserted");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
Reply
Answers (
2
)
How to add datetimepicker in datagridview ComboBox Column ?
How to read pdf line by line and fetch the data in c#