I have deleted all records from database now no records in my database.
but when form loaded then records show in my form.
anyone please help.why this problem coming.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Sql;
namespace MyProject
{
public partial class Form1 : Form
{
DataTable tbl = new DataTable();
int i = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
RefreshData();
}
private void display(DataTable tbl)
{
txtempid.Text = tbl.Rows[i][0].ToString();
txtname.Text = tbl.Rows[i][1].ToString();
txtsurname.Text = tbl.Rows[i][2].ToString();
txtfathername.Text = tbl.Rows[i][3].ToString();
dtdob.Text = tbl.Rows[i][4].ToString();
cbgender.Text = tbl.Rows[i][5].ToString();
cbcity.Text = tbl.Rows[i][6].ToString();
txtcontactno.Text = tbl.Rows[i][7].ToString();
dtdoj.Text = tbl.Rows[i][8].ToString();
txtdept.Text = tbl.Rows[i][9].ToString();
txtdesig.Text = tbl.Rows[i][10].ToString();
txtqualification.Text = tbl.Rows[i][11].ToString();
rtaddress.Text = tbl.Rows[i][12].ToString();
rtremarks.Text = tbl.Rows[i][13].ToString();
}
private void button4_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\manish\Documents\HRM.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
conn.Open();
SqlCommand command = new SqlCommand();
command.CommandText = "insert into emp_detail(empid,name,surname,fathername,dob,gender,city,contactno,doj,department,designation,qualification,address,remarks) values('" + txtempid.Text + "','" + txtname.Text + "','" + txtsurname.Text + "','" + txtfathername.Text + "','" + dtdob.Text + "','" + cbgender.Text + "','" + cbcity.Text + "','" + txtcontactno.Text + "','" + dtdoj.Text + "','" + txtdept.Text + "','" + txtdesig.Text + "','" + txtqualification.Text + "','" + rtaddress.Text + "','" + rtremarks.Text + "')";
command.Connection = conn;
command.ExecuteNonQuery();
MessageBox.Show("Saving is done!");
}
private void RefreshData()
{
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\manish\Documents\HRM.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
conn.Open();
SqlCommand command = new SqlCommand("select * from emp_detail", conn);
SqlDataAdapter adp = new SqlDataAdapter(command);
adp.Fill(tbl);
display(tbl);
}