hi i want to show my table in dataGridView but its shows the error that
specified cast is not valid
i am working in c# windows application
my code is here .Actually i know second method to show from database in dataGridView but my sir wants to show like as
dataGridView1.Columns.Add("1","User Login Id");
dataGridView1.Columns.Add("2", "Employee Id");
dataGridView1.Columns.Add("3", "Serial No");
dataGridView1.Columns.Add("4", "Enroll Date");
and my complete code here
public partial class frmenrolldetails : Form
{
DBConnect dbcon = new DBConnect();
Timer timer1 = new Timer();
public frmenrolldetails()
{
InitializeComponent();
}
private void frmenrolldetails_Load(object sender, EventArgs e)
{
timer1.Start();
timer1.Tick +=new EventHandler(timer1_Tick);
dataGridView1.Columns.Add("1", "User Login Id");
dataGridView1.Columns.Add("2", "Employee Id");
dataGridView1.Columns.Add("3", "Enroll Serial No");
dataGridView1.Columns.Add("4", "Enroll Date");
BindGrid();
}
public void BindGrid()
{
try
{
dbcon.OpenConnection();
string str = "select ulogin_id,emp_id,enroll_sno,enroll_dt from enroll_dtls";
OracleCommand cmd = new OracleCommand(str, DBConnect.connection);
OracleDataReader dr = cmd.ExecuteReader();
int rec = 0;
if (dr.HasRows)
{
while (dr.Read())
{
int n = dataGridView1.Rows.Add();
for (int i = 0; i < 4; i++)
{
dataGridView1.Rows[n].Cells[i].Value = dr.GetString(i);
}
rec++;
}
toolStripLabel1.Text = rec + " Records Found";
}
else
{
toolStripLabel1.Text = "No Records Found";
}
}
catch (OracleException err)
{
MessageBox.Show(err.Message);
}
}
void timer1_Tick(object ob, EventArgs e)
{
toolStripLabel2.Text = DateTime.Now.ToString();
}
}
}
so please help me here