forum

Home / DeveloperSection / Forums / How to embed asp.net with SQL Server reading data and changing textbox field?

How to embed asp.net with SQL Server reading data and changing textbox field?

Barbara Jones 1650 29-Jan-2015

I am creating a sql project. I used a SqlDatareader and textbox, but when I run it I got an error

InvalidOperationException

My code is this, thanks for your help.

    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedIndex == 0)
        {
                string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                using (SqlConnection con = new SqlConnection(CS))
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand
                        ("USE [PRODUCTS] SELECT QUALITIES FROM dbo.COMPUTERS WHERE ID = 0", con);
                    SqlDataReader reader;
                    reader = cmd.ExecuteReader();
                    TextBox1.Text = reader["QUALITIES"].ToString();
                }
            }
        }


Updated on 29-Jan-2015

Can you answer this question?


Answer

1 Answers

Liked By