Hi Experts,

I use Visual Studio 2005.

I want to retreive data into textboxes providing inputs at runtime. I used the following code.It works when if i provide input at design time but while providing the input at run time the following error message gets displayed.

"Syntax error converting the varchar value 'TextBox10.Text' to a column of data type int. "

Please do help me in this regard.

Thanks in advance.

DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter("select * from success where au_id ='TextBox10.Text', "data source=.;initial catalog=joannes;user id=sa;password=joannes");
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count >= 0)
        {
            TextBox1.Text = ds.Tables[0].Rows[Convert.ToInt32(TextBox10.Text)]["au_id"].ToString();
            TextBox2.Text = ds.Tables[0].Rows[Convert.ToInt32(TextBox10.Text)]["au_lname"].ToString();
            TextBox3.Text = ds.Tables[0].Rows[Convert.ToInt32(TextBox10.Text)]["au_fname"].ToString();
            TextBox4.Text = ds.Tables[0].Rows[Convert.ToInt32(TextBox10.Text)]["phone"].ToString();
            TextBox5.Text = ds.Tables[0].Rows[Convert.ToInt32(TextBox10.Text)]["address"].ToString();
            TextBox6.Text = ds.Tables[0].Rows[Convert.ToInt32(TextBox10.Text)]["city"].ToString();
            TextBox7.Text = ds.Tables[0].Rows[Convert.ToInt32(TextBox10.Text)]["state"].ToString();
            TextBox8.Text = ds.Tables[0].Rows[Convert.ToInt32(TextBox10.Text)]["zip"].ToString();
            TextBox9.Text = ds.Tables[0].Rows[Convert.ToInt32(TextBox10.Text)]["contract"].ToString();
        }

Correction at line #2,

SqlDataAdapter da = new SqlDataAdapter("select * from success where au_id='" + TextBox10.Text + "'", "data source=.;initial catalog=joannes;user id=sa;password=joannes");

 da.Fill(ds);
        if (ds.Tables[0].Rows.Count >= 0)
        {
            TextBox1.Text = ds.Tables[0].Rows[0]["au_id"].ToString();
            TextBox2.Text = ds.Tables[0].Rows[0]["au_lname"].ToString();
            TextBox3.Text = ds.Tables[0].Rows[0]["au_fname"].ToString();
            TextBox4.Text = ds.Tables[0].Rows[0]["phone"].ToString();
            TextBox5.Text = ds.Tables[0].Rows[0]["address"].ToString();
            TextBox6.Text = ds.Tables[0].Rows[0]["city"].ToString();
            TextBox7.Text = ds.Tables[0].Rows[0]["state"].ToString();
            TextBox8.Text = ds.Tables[0].Rows[0]["zip"].ToString();
            TextBox9.Text = ds.Tables[0].Rows[0]["contract"].ToString();
        }
  ...
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.