DataSet Append Attempt Produces Error

S

Steven C

Hello:

I am trying to append a dataset that draws its data from a MSDE
instance, and I keep getting the exception:

Can't create a child list for field tblCustomers.



conn = new SqlConnection("Data Source=SWC_K7\\CHRISMON1;User
Id=yadda;password=yadda;Initial Catalog=ChrismonContacts");
DataSet CustomersDS = new DataSet();
string lcSql = "SELECT * " +
"FROM tblCustomers " +
"WHERE active = 1";
SqlDataAdapter CustomersAdapter = new SqlDataAdapter(lcSql,conn);
CustomersAdapter.Fill(CustomersDS,"tblCustomers");
DataTable CustomersTable = CustomersDS.Tables["tblCustomers"];
DataRow NewCustomersRow = CustomersTable.NewRow();
NewCustomersRow["customername"] =
Convert.ToString(this.tbCompanyName.Text);



Is there an easy and obvious explanation for this error? The
tblCustomers table has an integer primary key named customerno

Thanks!

Steven
 
W

William Ryan eMVP

Where are you getting the exception? I don't even see the row being added
to the table. I've essentially copied your logic and not had a problem.
 
S

Steven C

Thanks, William.

The full code snippet follows:

private void AppendDataset()
{
SqlConnection conn = null;
try
{
conn = new SqlConnection("Data
Source=SWC_K7\\CHRISMON1;User
Id=yadda;password=yadda;Initial
Catalog=ChrismonContacts");
DataSet CustomersDS = new DataSet();
string lcSql = "SELECT * " +
"FROM tblCustomers " +
"WHERE active = 1";
SqlDataAdapter CustomersAdapter = new
SqlDataAdapter(lcSql,conn);
CustomersAdapter.Fill(CustomersDS,"tblCustomers");
DataTable CustomersTable = CustomersDS.Tables["tblCustomers"];
DataRow NewCustomersRow = CustomersTable.NewRow();
NewCustomersRow["customername"] =
Convert.ToString(this.tbCompanyName.Text);

CustomersTable.Rows.Add(NewCustomersRow);

this.Dispose();

}
catch (SqlException sqle)
{
Console.WriteLine("Data Set Example SqlException:
{0}",sqle.Message);
MessageBox.Show("Not Able To Connect To SQL Server");
}
catch (Exception e)
{
Console.WriteLine("Generic Exception: {0}",e.Message);
}
}

The error that I'm getting is being written to the console via the
generic exception route.

Ideas?

Many thanks.

Steven

Where are you getting the exception? I don't even see the row being added
to the table. I've essentially copied your logic and not had a problem.
Hello:

I am trying to append a dataset that draws its data from a MSDE
instance, and I keep getting the exception:

Can't create a child list for field tblCustomers.



conn = new SqlConnection("Data Source=SWC_K7\\CHRISMON1;User
Id=yadda;password=yadda;Initial Catalog=ChrismonContacts");
DataSet CustomersDS = new DataSet();
string lcSql = "SELECT * " +
"FROM tblCustomers " +
"WHERE active = 1";
SqlDataAdapter CustomersAdapter = new SqlDataAdapter(lcSql,conn);
CustomersAdapter.Fill(CustomersDS,"tblCustomers");
DataTable CustomersTable = CustomersDS.Tables["tblCustomers"];
DataRow NewCustomersRow = CustomersTable.NewRow();
NewCustomersRow["customername"] =
Convert.ToString(this.tbCompanyName.Text);



Is there an easy and obvious explanation for this error? The
tblCustomers table has an integer primary key named customerno

Thanks!

Steven
 
W

William Ryan eMVP

What's with the this.Dispose? Also, which line is it that's throwing the
exception? That SqlException isn't catching it is it? Highly doubt it
could.
Thanks, William.

The full code snippet follows:

private void AppendDataset()
{
SqlConnection conn = null;
try
{
conn = new SqlConnection("Data
Source=SWC_K7\\CHRISMON1;User
Id=yadda;password=yadda;Initial
Catalog=ChrismonContacts");
DataSet CustomersDS = new DataSet();
string lcSql = "SELECT * " +
"FROM tblCustomers " +
"WHERE active = 1";
SqlDataAdapter CustomersAdapter = new
SqlDataAdapter(lcSql,conn);
CustomersAdapter.Fill(CustomersDS,"tblCustomers");
DataTable CustomersTable = CustomersDS.Tables["tblCustomers"];
DataRow NewCustomersRow = CustomersTable.NewRow();
NewCustomersRow["customername"] =
Convert.ToString(this.tbCompanyName.Text);

CustomersTable.Rows.Add(NewCustomersRow);

this.Dispose();

}
catch (SqlException sqle)
{
Console.WriteLine("Data Set Example SqlException:
{0}",sqle.Message);
MessageBox.Show("Not Able To Connect To SQL Server");
}
catch (Exception e)
{
Console.WriteLine("Generic Exception: {0}",e.Message);
}
}

The error that I'm getting is being written to the console via the
generic exception route.

Ideas?

Many thanks.

Steven

Where are you getting the exception? I don't even see the row being added
to the table. I've essentially copied your logic and not had a problem.
Hello:

I am trying to append a dataset that draws its data from a MSDE
instance, and I keep getting the exception:

Can't create a child list for field tblCustomers.



conn = new SqlConnection("Data Source=SWC_K7\\CHRISMON1;User
Id=yadda;password=yadda;Initial Catalog=ChrismonContacts");
DataSet CustomersDS = new DataSet();
string lcSql = "SELECT * " +
"FROM tblCustomers " +
"WHERE active = 1";
SqlDataAdapter CustomersAdapter = new SqlDataAdapter(lcSql,conn);
CustomersAdapter.Fill(CustomersDS,"tblCustomers");
DataTable CustomersTable = CustomersDS.Tables["tblCustomers"];
DataRow NewCustomersRow = CustomersTable.NewRow();
NewCustomersRow["customername"] =
Convert.ToString(this.tbCompanyName.Text);



Is there an easy and obvious explanation for this error? The
tblCustomers table has an integer primary key named customerno

Thanks!

Steven
 
S

Steven C

Hello:

The "this.dispose" is supposed to release the form when the append
operation is complete. I'm kind of new to C#, so is that not the way
to do that?

Also, how do I grab the line number in the Try / Catch code? Right
now, I'm just reporting the error message itself, ie, "catch
(Exception e)"

Thanks!

Steven

What's with the this.Dispose? Also, which line is it that's throwing the
exception? That SqlException isn't catching it is it? Highly doubt it
could.
Thanks, William.

The full code snippet follows:

private void AppendDataset()
{
SqlConnection conn = null;
try
{
conn = new SqlConnection("Data
Source=SWC_K7\\CHRISMON1;User
Id=yadda;password=yadda;Initial
Catalog=ChrismonContacts");
DataSet CustomersDS = new DataSet();
string lcSql = "SELECT * " +
"FROM tblCustomers " +
"WHERE active = 1";
SqlDataAdapter CustomersAdapter = new
SqlDataAdapter(lcSql,conn);
CustomersAdapter.Fill(CustomersDS,"tblCustomers");
DataTable CustomersTable = CustomersDS.Tables["tblCustomers"];
DataRow NewCustomersRow = CustomersTable.NewRow();
NewCustomersRow["customername"] =
Convert.ToString(this.tbCompanyName.Text);

CustomersTable.Rows.Add(NewCustomersRow);

this.Dispose();

}
catch (SqlException sqle)
{
Console.WriteLine("Data Set Example SqlException:
{0}",sqle.Message);
MessageBox.Show("Not Able To Connect To SQL Server");
}
catch (Exception e)
{
Console.WriteLine("Generic Exception: {0}",e.Message);
}
}

The error that I'm getting is being written to the console via the
generic exception route.

Ideas?

Many thanks.

Steven

Where are you getting the exception? I don't even see the row being added
to the table. I've essentially copied your logic and not had a problem.
<Steven C> wrote in message
Hello:

I am trying to append a dataset that draws its data from a MSDE
instance, and I keep getting the exception:

Can't create a child list for field tblCustomers.



conn = new SqlConnection("Data Source=SWC_K7\\CHRISMON1;User
Id=yadda;password=yadda;Initial Catalog=ChrismonContacts");
DataSet CustomersDS = new DataSet();
string lcSql = "SELECT * " +
"FROM tblCustomers " +
"WHERE active = 1";
SqlDataAdapter CustomersAdapter = new SqlDataAdapter(lcSql,conn);
CustomersAdapter.Fill(CustomersDS,"tblCustomers");
DataTable CustomersTable = CustomersDS.Tables["tblCustomers"];
DataRow NewCustomersRow = CustomersTable.NewRow();
NewCustomersRow["customername"] =
Convert.ToString(this.tbCompanyName.Text);



Is there an easy and obvious explanation for this error? The
tblCustomers table has an integer primary key named customerno

Thanks!

Steven
 
R

Ron Allen

Steven,
You want this.Close(); to close a form call Dispose where it was created
to clean up. Also e.StackTrace will show the actual line # of the error in
Debug mode.

Ron Allen
Hello:

The "this.dispose" is supposed to release the form when the append
operation is complete. I'm kind of new to C#, so is that not the way
to do that?

Also, how do I grab the line number in the Try / Catch code? Right
now, I'm just reporting the error message itself, ie, "catch
(Exception e)"

Thanks!

Steven

What's with the this.Dispose? Also, which line is it that's throwing the
exception? That SqlException isn't catching it is it? Highly doubt it
could.
Thanks, William.

The full code snippet follows:

private void AppendDataset()
{
SqlConnection conn = null;
try
{
conn = new SqlConnection("Data
Source=SWC_K7\\CHRISMON1;User
Id=yadda;password=yadda;Initial
Catalog=ChrismonContacts");
DataSet CustomersDS = new DataSet();
string lcSql = "SELECT * " +
"FROM tblCustomers " +
"WHERE active = 1";
SqlDataAdapter CustomersAdapter = new
SqlDataAdapter(lcSql,conn);
CustomersAdapter.Fill(CustomersDS,"tblCustomers");
DataTable CustomersTable = CustomersDS.Tables["tblCustomers"];
DataRow NewCustomersRow = CustomersTable.NewRow();
NewCustomersRow["customername"] =
Convert.ToString(this.tbCompanyName.Text);

CustomersTable.Rows.Add(NewCustomersRow);

this.Dispose();

}
catch (SqlException sqle)
{
Console.WriteLine("Data Set Example SqlException:
{0}",sqle.Message);
MessageBox.Show("Not Able To Connect To SQL Server");
}
catch (Exception e)
{
Console.WriteLine("Generic Exception: {0}",e.Message);
}
}

The error that I'm getting is being written to the console via the
generic exception route.

Ideas?

Many thanks.

Steven


Where are you getting the exception? I don't even see the row being added
to the table. I've essentially copied your logic and not had a problem.
<Steven C> wrote in message
Hello:

I am trying to append a dataset that draws its data from a MSDE
instance, and I keep getting the exception:

Can't create a child list for field tblCustomers.



conn = new SqlConnection("Data Source=SWC_K7\\CHRISMON1;User
Id=yadda;password=yadda;Initial Catalog=ChrismonContacts");
DataSet CustomersDS = new DataSet();
string lcSql = "SELECT * " +
"FROM tblCustomers " +
"WHERE active = 1";
SqlDataAdapter CustomersAdapter = new SqlDataAdapter(lcSql,conn);
CustomersAdapter.Fill(CustomersDS,"tblCustomers");
DataTable CustomersTable = CustomersDS.Tables["tblCustomers"];
DataRow NewCustomersRow = CustomersTable.NewRow();
NewCustomersRow["customername"] =
Convert.ToString(this.tbCompanyName.Text);



Is there an easy and obvious explanation for this error? The
tblCustomers table has an integer primary key named customerno

Thanks!

Steven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top