Hi,
I developed a webpage in which the first page contains a textbox in which if we enter a customer name and click button get details it should display all the details from database. in another page i have written code to insert values into database. the values are getting inserted into database. but when i am trying to display the details from database in am getting an error.
i am posting code as follows.
for the start page code is as follows:

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Server.Transfer("CustomerDetails.aspx");
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string connectstring = @"Data Source=localhost;Initial Catalog=proj;User ID=sa;Password=aravinda";
        SqlConnection conn = new SqlConnection(connectstring);
        conn.Open();
        String sql = "select * from CustomerDetails where CustomerName = "+TextBox1.Text;
        SqlCommand cmd = new SqlCommand(sql, conn);
        SqlDataReader reader = cmd.ExecuteReader();
        reader.Read();

        TextBox2.Text = reader[1].ToString();
        TextBox3.Text = reader[2].ToString();
        TextBox4.Text = reader[3].ToString();
        TextBox5.Text = reader[4].ToString();
        TextBox6.Text = reader[5].ToString();
        TextBox7.Text = reader[6].ToString();
        TextBox8.Text = reader[7].ToString();
        reader.Close();
        conn.Close();

    }

for the customer details page ie to insert values into database code is as foloows. this page is working fine. it is inserting values into databse.

protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=proj;Persist Security Info=True;User ID=sa;Password=aravinda" );
        string query = "insert into CustomerDetails values(@CustomerName,@Address,@Street,@City,@State,@ZipCode,@Attn,@EmailId)";
        SqlCommand cmd = new SqlCommand(query, conn);
        cmd.Parameters.Add(new SqlParameter("@CustomerName", SqlDbType.VarChar, 50));
        cmd.Parameters["@CustomerName"].Value = TextBox1.Text;
        cmd.Parameters.Add(new SqlParameter("@Address", SqlDbType.VarChar, 50));
        cmd.Parameters["@Address"].Value = TextBox2.Text;
        cmd.Parameters.Add(new SqlParameter("@Street", SqlDbType.VarChar, 50));
        cmd.Parameters["@Street"].Value = TextBox3.Text;
        cmd.Parameters.Add(new SqlParameter("@City", SqlDbType.VarChar, 50));
        cmd.Parameters["@City"].Value = TextBox4.Text;
        cmd.Parameters.Add(new SqlParameter("@State", SqlDbType.VarChar, 50));
        cmd.Parameters["@State"].Value = TextBox5.Text;
        cmd.Parameters.Add(new SqlParameter("@ZipCode", SqlDbType.NChar, 50));
        cmd.Parameters["@ZipCode"].Value = TextBox6.Text;
        cmd.Parameters.Add(new SqlParameter("@Attn", SqlDbType.VarChar, 50));
        cmd.Parameters["@Attn"].Value = TextBox7.Text;
        cmd.Parameters.Add(new SqlParameter("@EmailId", SqlDbType.VarChar, 50));
        cmd.Parameters["@EmailId"].Value = TextBox8.Text;    
        cmd.Connection.Open();
        cmd.ExecuteNonQuery();
        cmd.Connection.Close();

    }

i am facing problem only in first page where i am trying to display values from the database which are already inserted . can someone plz help me.

You are in the wrong forum... There is an ASP.NET forum under the Web Development tab.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.