I am doing an insertion operation, But every time I am getting one error in line:
DataRow row = ds.Tables[0].NewRow();
Saying,
Nullreferenceexception Was Unhandled.
Here is my code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace employeDB1
{
public partial class Insert : Form
{
public Insert()
{
InitializeComponent();
}
DatabaseConnection objConnect;
int inc = 0;
int MaxRows;
DataSet ds;
private void Insert_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
DataRow row = ds.Tables[0].NewRow();
row[1] = int.Parse(textBox1.Text);
row[2] = textBox2.Text;
row[3] = textBox3.Text;
row[4] = int.Parse(textBox4.Text);
ds.Tables[0].Rows.Add(row);
try
{
objConnect.UpdateDatabase(ds);
MaxRows = MaxRows + 1;
inc = MaxRows - 1;
MessageBox.Show("RECORD INSERTED");
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
}
}
}