Asp.Net ?

well i want retrieve data from sql to my . net page.. i have a set a combo box.. where all user name have to be stored . one selecting any name all other values should be displayed.. i wrote this coding but i get error.
SqlConnection con = new SqlConnection(“Data Source=ORG-99DBE221248;Initial Catalog=pubs;Integrated Security=True”);
String sName = “select * from feedback where uname='” + cuname.Text + “‘”;

email.Text = email ;
sites.Text = site ;
pro.Text= pro ;
cm.Text = cm ;
qa.Text = aq;
sug.Text = Sug ;
Qlike.Text = Qlike ;
dislike.Text = dislike ;
SqlCommand cmd = new SqlCommand(sName,con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
Error are shown where i assign text box and sql value… can anybody rectify this error plz. i use c# language

2 thoughts on “Asp.Net ?”

  1. Try this code. And dont use String concat operations.
    using( SqlConnection connection = new SqlConnection(“Data Source=ORG-99DBE221248;Initial Catalog=pubs;Integrated Security=True”) )
    {
    SqlCommand command = new SqlCommand(“SELECT * FROM feedback WHERE ( UNAME = @UNAME )”);
    command.Parameters.Add(“@UNAME”, SqlDbTypes.Text) = cuname.Text;

    SqlDataReader reader = null;
    try
    {
    connection.Open();
    reader = command.ExecuteReader();
    if ( reader.HasRows )
    {
    while ( reader.Read() )
    {
    email.Text = reader.GetString( database table field index like 0 );
    if email columns first column in the table then you must use 0 for first column
    email.Text = reader.GetString(0);
    sites.Text = reader.GetString(1);
    }

    reader.Close();
    }
    connection.Close();
    reader.Dispose();
    } catch ( SqlException ex )
    {
    // Handle errors
    } // End Try
    } / / End U”sing

  2. Looking at this code it seems you are assigning email.Text = email etc.. before you run the actual query.

    Are you sure you are getting a result back from your query? Print out the query and run it from the database to make sure the query actually returns a result.

Leave a Reply

Your email address will not be published. Required fields are marked *