anyone help me please...


G

Guest

my prog works like this...i had created a summary report form where there is
a text box, data grid and a button. when the user enter the customer id in
the text box and press the button, the data grid will show the particulars
about that customer id only....may i know how to pass the value from that
text box to the database and display the value? below are my part of my
program:

SqlDataReader rdr = null;
con = null;
SqlCommand cmd = null;
try
{
// Open connection to the database
string ConnectionString
= "server=CPQ82156712159; database=Call Billing System";
con = new SqlConnection(ConnectionString);
con.Open();
// Set up a command with the given query and associate
// this with the current connection.
string CommandText = "SELECT Cust_ID" +
" FROM Call_Details_Record";
cmd = new SqlCommand(CommandText);
cmd.Connection = con;
rdr = cmd.ExecuteReader();
while(rdr.Read())
{
textBox1.Text = rdr["Cust_ID"].ToString();

}

}
catch(Exception ex)
{
// Print error message
MessageBox.Show(ex.Message);
}
finally
{
// Close data reader object and database connection
if (rdr != null)
rdr.Close();

if (con.State == ConnectionState.Open)
con.Close();
}
Please tell me what to do in a detail steps...thanks...ur help is much
appreciated...
 
Ad

Advertisements

N

Nick Malik [Microsoft]

change the following lines
string CommandText = "SELECT Cust_ID" +
" FROM Call_Details_Record Where Cust_ID = '" + MyTextBox.Text + "'";

This is not the preferred way to do this, but I don't want to overwhelm you
with details. You are clearly a novice.

May I suggest that you could really benefit from a training course, or a
book that would walk you through a complex example step-by-step?

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top