help!i'm stuck here

G

Guest

SqlDataReader rdr = null;
SQLConnection con = null;
SqlCommand cmd = null;
try
{
// Open connection to the database
string ConnectionString = "server=localhost;database =
CallBilling 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();
}

This is part of the program and it goes like this this-->when the user enter
the customer id in the text box and press the button, it will search in the
table for the activities about that customer id and display out in the data
grid. I don't know how to match the value from the text box with the customer
id in the table and display out in the data grid....do i do anything
wrong?please correct my mistakes or any suggestion or coding
welcome....thanks..
 
V

VJ

SqlDataReader rdr = null;
SQLConnection con = null;
SqlCommand cmd = null;
try
{
// Open connection to the database
string ConnectionString = "server=localhost;database = CallBilling
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 Where Cust_ID = " + textBox1.Text;
SqlDataAdapter sqlda = new SqlDataAdapter(CommandText,con);
DataSet dsCust = new DataSet();
sqlda.Fill(dsCust,"CustInfo");
//Use ur DataGrid here..
DataGrid myDataGrid = new DataGrid();
myDataGrid.DataSource = dsCust;
//Optionally you can add Styles.. and set column properties
}
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();
}

HTH
VJ
 
G

Guest

I have tried your code but my data grid dsplay all the particular of all the
customers and not the customer id that is entered in the text box..may u give
me more detail explaination?thanks

VJ said:
SqlDataReader rdr = null;
SQLConnection con = null;
SqlCommand cmd = null;
try
{
// Open connection to the database
string ConnectionString = "server=localhost;database = CallBilling
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 Where Cust_ID = " + textBox1.Text;
SqlDataAdapter sqlda = new SqlDataAdapter(CommandText,con);
DataSet dsCust = new DataSet();
sqlda.Fill(dsCust,"CustInfo");
//Use ur DataGrid here..
DataGrid myDataGrid = new DataGrid();
myDataGrid.DataSource = dsCust;
//Optionally you can add Styles.. and set column properties
}
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();
}

HTH
VJ
alyssa said:
SqlDataReader rdr = null;
SQLConnection con = null;
SqlCommand cmd = null;
try
{
// Open connection to the database
string ConnectionString = "server=localhost;database =
CallBilling 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();
}

This is part of the program and it goes like this this-->when the user
enter
the customer id in the text box and press the button, it will search in
the
table for the activities about that customer id and display out in the
data
grid. I don't know how to match the value from the text box with the
customer
id in the table and display out in the data grid....do i do anything
wrong?please correct my mistakes or any suggestion or coding
welcome....thanks..
 
V

VJ

oh wow.. ok.. change the following & try... the below code has worked for me
always...anyway give the below try

string CommandText = "SELECT Cust_ID" +
" FROM Call_Details_Record Where Cust_ID = " + int.parse(textBox1.Text);

alyssa said:
I have tried your code but my data grid dsplay all the particular of all
the
customers and not the customer id that is entered in the text box..may u
give
me more detail explaination?thanks

VJ said:
SqlDataReader rdr = null;
SQLConnection con = null;
SqlCommand cmd = null;
try
{
// Open connection to the database
string ConnectionString = "server=localhost;database = CallBilling
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 Where Cust_ID = " + textBox1.Text;
SqlDataAdapter sqlda = new SqlDataAdapter(CommandText,con);
DataSet dsCust = new DataSet();
sqlda.Fill(dsCust,"CustInfo");
//Use ur DataGrid here..
DataGrid myDataGrid = new DataGrid();
myDataGrid.DataSource = dsCust;
//Optionally you can add Styles.. and set column properties
}
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();
}

HTH
VJ
alyssa said:
SqlDataReader rdr = null;
SQLConnection con = null;
SqlCommand cmd = null;
try
{
// Open connection to the database
string ConnectionString = "server=localhost;database =
CallBilling 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();
}

This is part of the program and it goes like this this-->when the user
enter
the customer id in the text box and press the button, it will search in
the
table for the activities about that customer id and display out in the
data
grid. I don't know how to match the value from the text box with the
customer
id in the table and display out in the data grid....do i do anything
wrong?please correct my mistakes or any suggestion or coding
welcome....thanks..
 

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