try
{
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Name", typeof(string));
DataRow dr = dt.NewRow();
dr["ID"] = 100;
dr["Name"] = "Bala";
dt.Rows.Add(dr);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
UPDATE 1
1. Hope your dataset is declared as follows
public partial class Form1 : Form
{
DataSet ds = new DataSet();
public Form1()
{
InitializeComponent();
}
2. Hope you data binding is as follows
try
{
SqlConnection oconn = new SqlConnection();
oconn.ConnectionString = "Data Source=Localhost;Initial Catalog=TEST_DB;user=sa;password=123";
oconn.Open();
SqlDataAdapter oda = new SqlDataAdapter("Select ID,Name from employees", oconn);
oda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
3. You can add a new row to the table which is attached to a dataset as follows
private void btnAdd_Click(object sender, EventArgs e)
{
try
{
DataRow dr = ds.Tables[0].NewRow();
dr["name"] = "bala";
ds.Tables[0].Rows.Add(dr);
}
catch (Exception ex)
{
}
}