Skip to content

DLA

Olajide Adefuye

Asked Dec 7, 2005, 5:46 AM EST1 answer
Share
LinkedInX
I am writing a code that will bind data to a textbox when a button is click and could not retrive the data from the database and bind it to the textbox  this are my code please tell me where my code is wrong

private void button1_Click(object sender, System.EventArgs e)

{

button1.Focus();try

{

SqlConnection con=new SqlConnection("server=gidafi;uid=sa;pwd=sa;database=pubs");

SqlCommand sqlcom=new SqlCommand("select * from jobs",con);

SqlDataAdapter sqldpt=new SqlDataAdapter();

sqldpt.SelectCommand=sqlcom;

DataSet ds=new DataSet();

con.Open();

sqldpt.Fill(ds,"jobs");

textBox1.DataBindings("Text", ds ,"job_id");

textBox2.DataBindings.Add("Text", ds ,"job_des");

textBox3.DataBindings.Add("Text", ds ,"min_lvl");

textBox4.DataBindings.Add("Text", ds ,"max_lvl");

con.Close();

}

catch(Exception f){MessageBox.Show("what"+f);}
__________________________________________________
I'm using SQL2000 server database

exception generated by the code is WhatSystem.ArgumentException;Cannot bind to property or column job_id Datasource

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Do you get any Exceptions? Please post them here, so we can help you better.

    What kind of a database you use? Slq-classes are only for Microsoft SqlServer databases. If you use any other database than SqlServer (Access for example), you must use OleDb-classes instead, and appropriate connection string when creating OleDbConnection.

    Double check database table and column names.

    This line seems to be wrong:
    textBox1.DataBindings("Text", ds ,"job_id");
    0