Hemal Joshi

Hemal Joshi

  • NA
  • 78
  • 48.5k

Display Specific data in data grid when click on button

Jan 15 2018 8:11 AM
Hello All,
 
I am create a Windows form which have 2 lables like Start No and End No and according that lable i have put two textboxes now i want to display data when i click on the show button it display data form Start No to End No to data gridview and if no text entered and click on show it will raise an No Record Found Error.
 
EX: Start No: 1
       End No: 5 and then click on Show button it will disply only 1 to 5 records in gridview.
 
Update my Code according to requirement.
 
Design: 
 
 
Here My Code Is:
 
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;
using System.Data.SqlClient;
using System.Configuration;
namespace DemoLogin
{
public partial class WorkingMembers : Form
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyCon"].ConnectionString);
public WorkingMembers()
{
InitializeComponent();
}
private void btnShow_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from MMMEMBER",con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.ColumnCount = 9;
//Add Columns
dataGridView1.Columns[0].Name = "MNO";
dataGridView1.Columns[0].HeaderText = "MNO";
dataGridView1.Columns[0].DataPropertyName = "MNO";
dataGridView1.Columns[1].Name = "MNAME";
dataGridView1.Columns[1].HeaderText = "MNAME";
dataGridView1.Columns[1].DataPropertyName = "MNAME";
dataGridView1.Columns[2].Name = "MNAME1";
dataGridView1.Columns[2].HeaderText = "MNAME1";
dataGridView1.Columns[2].DataPropertyName = "MNAME1";
dataGridView1.Columns[3].Name = "NOMINY";
dataGridView1.Columns[3].HeaderText = "NOMINY";
dataGridView1.Columns[3].DataPropertyName = "NOMINY";
dataGridView1.Columns[4].Name = "ADD1";
dataGridView1.Columns[4].HeaderText = "ADD1";
dataGridView1.Columns[4].DataPropertyName = "ADD1";
dataGridView1.Columns[5].Name = "CITY";
dataGridView1.Columns[5].HeaderText = "CITY";
dataGridView1.Columns[5].DataPropertyName = "CITY";
dataGridView1.Columns[6].Name = "OP_DT";
dataGridView1.Columns[6].HeaderText = "OP_DT";
dataGridView1.Columns[6].DataPropertyName = "OP_DT";
dataGridView1.Columns[7].Name = "PHONE1";
dataGridView1.Columns[7].HeaderText = "PHONE1";
dataGridView1.Columns[7].DataPropertyName = "PHONE1";
dataGridView1.Columns[8].Name = "CU_SH_AMT";
dataGridView1.Columns[8].HeaderText = "CU_SH_AMT";
dataGridView1.Columns[8].DataPropertyName = "CU_SH_AMT";
dataGridView1.DataSource = dt;
con.Close();
}
}
}
 
 
 

Answers (5)