Here is an example with just enough to provide a solution. Note your two columns as shown should never compile as you have both column names the same name.
using System;
using System.Data;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class StuDetForm : Form
{
public StuDetForm()
{
InitializeComponent();
}
public static DataSet stuDetDataSet = new DataSet("StuDetDataSet");
public static BindingSource stuDetBindingSource = new BindingSource();
private void Cre_stuDetDataTable_Col()
{
var stuDetDataTable = new DataTable("StuDet");
var stuIdColumn = new DataColumn
{
DataType = typeof(string),
ColumnName = "StuId"
};
var stuNamColumn = new DataColumn
{
DataType = typeof(string),
ColumnName = "StuNam"
};
stuDetDataTable.Columns.AddRange(new[] {stuIdColumn, stuNamColumn});
stuDetDataSet.Tables.Add(stuDetDataTable);
stuDetBindingSource.DataMember = "StuDet";
stuDetBindingSource.DataSource = stuDetDataSet.Tables["StuDet"];
stuDetDataGridView.DataSource = stuDetBindingSource;
}
private void Form1_Load(object sender, EventArgs e)
{
Cre_stuDetDataTable_Col();
}
private void AddRow_Click(object sender, EventArgs e)
{
var dataTable = (DataTable) stuDetBindingSource.DataSource;
DataRow StuDetNewRow;
StuDetNewRow = dataTable.NewRow();
StuDetNewRow["StuId"] = "7452";
StuDetNewRow["StuNam"] = "Reno";
dataTable.Rows.Add(StuDetNewRow);
}
}
}