Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
object reference is not set to an instance of an object
Viswa Kousika
Dec 9 2016 3:33 AM
248
Reply
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());
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
How to add datetimepicker in datagridview ComboBox Column ?
How to read pdf line by line and fetch the data in c#