0

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();
        }

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

2
Contributors
1
Reply
8
Views
7 Years
Discussion Span
Last Post by __avd
2

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();
        }
  ...
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.