Click here to Skip to main content
15,923,083 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I've been reading lots of tutorial about handling database but still dont how to do it. My main problem is that i want to use a textbox and a button to search my database and then displays results in a new form's textboxes. By the way i'm using visualstudio2010(c#). sorry for the bad english.

ex:

searchform: search ID: (this is a textbox) //Enters student ID to search


resultform: search ID: 200489 // displays result in texboxes


thank you so much in advance. any help would be greatly appreciated.
Posted
Comments
Sergey Alexandrovich Kryukov 26-Dec-11 23:18pm    
My best advise would be: keep reading. Others could do it, so why not you?
--SA

hi ram,

pass query like this

your getting records through

select * from table_name where searchid='"+txtsearchid.text+"';
 
Share this answer
 
v2
hello ramcab,

you can search your record on button click event after enter the id in textbox. and store the result in session or query string to pass to another form. and set that value in texbox of that form.
loke :
C#
Session["name_of_student"]=abc; /* abc is string that contains your data like name of student. */

use Response.Redirect() or what ever you wanna use to open new form.
and set value like :
C#
txtbox.Text=Session["name_of_student"].ToString();

Hope this will help you.
Don't forget to mark as answer if it helps. :)
 
Share this answer
 
You Can Use Query Like this
Select * from tblstudent where searchId='"+txtid.text+"'
like this
 
Share this answer
 
thank you very much for your answers sir's, the pulling of records from the database, i've done it. but what i need is to call those records in another form. i have 2 forms. in form1 I have a button and textbox where i'll type the data to be search and display result in form2's textboxes.

ex:
form1:
search student: (enter student ID) <---textbox

form2:
Student ID is : (result in textbox)
Firstname: (result in textbox)
Lastname: (result in textbox)

this is what i have coded so far but result is displayed at the same form.

namespace PCU_CEIT
{
public partial class searchstud : Form
{
private OleDbConnection connection;
private OleDbCommand command;
private OleDbDataAdapter adapter;
private OleDbCommandBuilder builder;
private DataSet dataSet;



public searchstud()
{
InitializeComponent();
connection = new OleDbConnection();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\PrincessGHY\Desktop\CEIT\dummystud.accdb";
command = connection.CreateCommand();
adapter = new OleDbDataAdapter(command);
builder = new OleDbCommandBuilder(adapter);
dataSet = new DataSet();
}

private void button6_Click(object sender, EventArgs e)
{
{
command.CommandText = "SELECT * FROM studentinfo WHERE StudID=@StudID";
command.Parameters.Clear();
command.Parameters.AddWithValue("@studID", txtsearch.Text);

dataSet.Tables.Clear();

int result = adapter.Fill(dataSet, "studentinfo");

if (result > 0)
{
studinfo stdinf = new studinfo();
stdinf.Show();
DataRow studentinfo = dataSet.Tables["studentinfo"].Rows[0];
textBox1.Text = studentinfo["FirstName"].ToString();
textBox2.Text = studentinfo["LastName"].ToString();
}
else
{
MessageBox.Show("Student does not exist.");
}
}

sorry for bothering you guys but thanks a lot for the help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900