TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mayank Jani
NA
477
76.6k
How to fetch data in a perticular desired gridview cell?
Jul 5 2017 9:37 AM
Hiiii,
i am working on a windows form with C# and MS Access database. a form contains a DataGridView and a TextBox.
there are many fields in the table but, i want only four items to be displayed in the gridview, the gridview is created at the time of the form load event and when emp_id to be enter in the text box, it fetches the record from database to the gridview... please see the code...
//when form loads.
private void frmReception_Load(object sender, EventArgs e)
{
dgvEmp.ColumnCount = 2; //Create gridview for Emp.
dgvEmp.RowCount = 2;
dgvEmp.Columns[0].Width = 293;
dgvEmp.Columns[1].Width = 293;
dgvEmp.Rows[0].Height = 38;
dgvEmp.Rows[1].Height = 38;
}
//when searching a record
private void txtEmpNo_Validated(object sender, EventArgs e)
{
if (txtEmpNo.Text.Trim() == "")
{
return;
}
else
{
OleDbDataAdapter SearchEmp = new OleDbDataAdapter("Select EmpFullName, EmpDOB, EmpMobileNumber, EmpCity From Patient Where EmpCaseNo='" + txtEmpNo.Text + "'", MyConn);
DataSet dsSearchEmp = new DataSet();
SearchEmp.Fill(dsSearchEmp);
if (dsSearchEmp.Tables[0].Rows.Count > 0)
{
dgvEmp.DataSource = dsSearchEmp.Tables[0]; //this gives result but creates new gridview
dgvEmp.Rows[0].Cells[1].Value = dsSearchEmp.Tables[0].Rows[0].ItemArray[2].ToString(); //not working
}
else
{
MessageBox.Show("No Record Found.", "Oops...");
txtEmpNo.Text = "";
return;
}
}
}
i want to display the four results in four cells that i have created at the time of form load but it shows not according to that. the dataset creates new gridview and appends.
please suggest me what to do? is there any function or something that help me to do as i mentioned?
thank you.
Mayank Jani.
Reply
Answers (
2
)
Save data selected from dropdownlist to excel in MVC
SqLite DataBase Locked Exception