MS Chaudhary


Hello
while trying to bind data to my textfield i get this error
"child list for field line cannot be created"


DataBaseHandler is my self defined class which just manages the connections to the database returns the dataset.
databse name=student
table name=line
following is the code im using

DataBaseHandler db = new DataBaseHandler("mouse_handling.Properties.Settings.studentConnectionString");
DataSet ds = new DataSet();
ds=db.getdata("select * from line ");
if (ds.Tables.Count > 0)
textBox1.DataBindings.Add("Text", ds, "line.area");
else
MessageBox.Show("therez no data");



Re: Windows Forms Data Controls and Databinding getting error while binding data to textfield.

franking

Hi,

does your DataBaseHandler set the DataTable::Name property

The exception means that no table called "line" could be found in the assigned dataset.

Hope this helps,

franking





Re: Windows Forms Data Controls and Databinding getting error while binding data to textfield.

MS Chaudhary

sorry
i've no idea how to do that.
this is the code of my databasehandler class

public class DataBaseHandler
{

private string connectionstring;
private SqlConnection con = null;
private string dbname;
private DataSet db_dataset;
private SqlDataAdapter db_adapter;

public DataBaseHandler(string DataBaseName)
{
this.dbname = DataBaseName;
}

private void connect()
{
string constr = ConfigurationManager.ConnectionStrings[dbname].ToString();
try
{
con = new SqlConnection(constr);
con.Open();

}
catch (Exception ex)
{
MessageBox.Show("Error in connection : " + ex.Message);
}


}
private void disconnect()
{
if (con != null)
con.Close();


}


public DataSet getdata(string query)
{
this.connect();
db_adapter = new SqlDataAdapter();
db_adapter.SelectCommand = new SqlCommand(query, con);
db_dataset = new DataSet();
db_adapter.Fill(db_dataset);
this.disconnect();
return db_dataset;

}




}







Re: Windows Forms Data Controls and Databinding getting error while binding data to textfield.

franking

try something like the following

Code Block

public DataSet getData(string query, string tableName)

{

...

db_adapter.Fill(db_dataset, tableName);

...

}

The DataAdapter will set the Name property for you.

Hope this helps,

franking





Re: Windows Forms Data Controls and Databinding getting error while binding data to textfield.

franking

I ment TableName property of course...sorry