There is an error in the line marked XXX
Could someone put it right for me?
Many thanks,
Adrian.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace WindowsApplication2
{
public class Form1 : System.Windows.Forms.Form
{

#region Windows Form Designer generated code
private System.Windows.Forms.ListBox listBox1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.Location = new System.Drawing.Point(16, 8);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(784, 238);
this.listBox1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(816, 266);
this.Controls.Add(this.listBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
using (SqlConnection my_connection = new SqlConnection("server =
fred\\sqlexpress; database = TrialDB; Integrated Security = TRUE;"))
{
string query = "SELECT Column_one, Column_two, Column_three FROM
dbo.Table_1 "+
"SELECT Column_one, Column_two, Column_three FROM dbo.Table_2";

using(SqlDataAdapter my_adapter = new
SqlDataAdapter(query,my_connection))
{

using(DataSet data_set = new DataSet())
{
my_adapter.TableMappings.Add("Tab", "bdo.Table_1");
my_adapter.TableMappings.Add("Tab1", "bdo.Table_2");
my_adapter.Fill(data_set,"Tab");

DataTable my_table = data_set.Tables["Tab"];

string display_string = string.Empty;

foreach(DataRow row in
my_table.Rows)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
{
for(int x = 0; x < 3; x++)
{
display_string += '\t' + (row.ItemArray[x].ToString());
}
listBox1.Items.Add(display_string);
display_string = string.Empty;
}
}
}
}
}
}

Re: Please help with some code. by Cor

Cor
Fri Jun 09 03:13:01 CDT 2006

And the error is?

:-)

Cor

"Adrian" <00@00.00> schreef in bericht
news:448926b2$0$713$5fc3050@dreader2.news.tiscali.nl...
> There is an error in the line marked XXX
> Could someone put it right for me?
> Many thanks,
> Adrian.
>
> using System;
> using System.Drawing;
> using System.Collections;
> using System.ComponentModel;
> using System.Windows.Forms;
> using System.Data;
> using System.Data.SqlClient;
>
> namespace WindowsApplication2
> {
> public class Form1 : System.Windows.Forms.Form
> {
>
> #region Windows Form Designer generated code
> private System.Windows.Forms.ListBox listBox1;
> private System.ComponentModel.Container components = null;
> public Form1()
> {
> InitializeComponent();
> }
> protected override void Dispose( bool disposing )
> {
> if( disposing )
> {
> if (components != null)
> {
> components.Dispose();
> }
> }
> base.Dispose( disposing );
> }
> private void InitializeComponent()
> {
> this.listBox1 = new System.Windows.Forms.ListBox();
> this.SuspendLayout();
> //
> // listBox1
> //
> this.listBox1.Location = new System.Drawing.Point(16, 8);
> this.listBox1.Name = "listBox1";
> this.listBox1.Size = new System.Drawing.Size(784, 238);
> this.listBox1.TabIndex = 0;
> //
> // Form1
> //
> this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
> this.ClientSize = new System.Drawing.Size(816, 266);
> this.Controls.Add(this.listBox1);
> this.Name = "Form1";
> this.Text = "Form1";
> this.Load += new System.EventHandler(this.Form1_Load);
> this.ResumeLayout(false);
>
> }
> #endregion
>
> [STAThread]
> static void Main()
> {
> Application.Run(new Form1());
> }
>
> private void Form1_Load(object sender, System.EventArgs e)
> {
> using (SqlConnection my_connection = new SqlConnection("server =
> fred\\sqlexpress; database = TrialDB; Integrated Security = TRUE;"))
> {
> string query = "SELECT Column_one, Column_two, Column_three FROM
> dbo.Table_1 "+
> "SELECT Column_one, Column_two, Column_three FROM dbo.Table_2";
>
> using(SqlDataAdapter my_adapter = new
> SqlDataAdapter(query,my_connection))
> {
>
> using(DataSet data_set = new DataSet())
> {
> my_adapter.TableMappings.Add("Tab", "bdo.Table_1");
> my_adapter.TableMappings.Add("Tab1", "bdo.Table_2");
> my_adapter.Fill(data_set,"Tab");
>
> DataTable my_table = data_set.Tables["Tab"];
>
> string display_string = string.Empty;
>
> foreach(DataRow row in
> my_table.Rows)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> {
> for(int x = 0; x < 3; x++)
> {
> display_string += '\t' + (row.ItemArray[x].ToString());
> }
> listBox1.Items.Add(display_string);
> display_string = string.Empty;
> }
> }
> }
> }
> }
> }
>
>



Re: Please help with some code. by Adrian

Adrian
Fri Jun 09 04:26:09 CDT 2006

> And the error is?
That I should have looped through the tables
as I have subsequently discovered.
Adrian.

"Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message
news:uEQdHx5iGHA.4748@TK2MSFTNGP04.phx.gbl...
> And the error is?
>
> :-)
>
> Cor
>
> "Adrian" <00@00.00> schreef in bericht
> news:448926b2$0$713$5fc3050@dreader2.news.tiscali.nl...
> > There is an error in the line marked XXX
> > Could someone put it right for me?
> > Many thanks,
> > Adrian.
> >
> > using System;
> > using System.Drawing;
> > using System.Collections;
> > using System.ComponentModel;
> > using System.Windows.Forms;
> > using System.Data;
> > using System.Data.SqlClient;
> >
> > namespace WindowsApplication2
> > {
> > public class Form1 : System.Windows.Forms.Form
> > {
> >
> > #region Windows Form Designer generated code
> > private System.Windows.Forms.ListBox listBox1;
> > private System.ComponentModel.Container components = null;
> > public Form1()
> > {
> > InitializeComponent();
> > }
> > protected override void Dispose( bool disposing )
> > {
> > if( disposing )
> > {
> > if (components != null)
> > {
> > components.Dispose();
> > }
> > }
> > base.Dispose( disposing );
> > }
> > private void InitializeComponent()
> > {
> > this.listBox1 = new System.Windows.Forms.ListBox();
> > this.SuspendLayout();
> > //
> > // listBox1
> > //
> > this.listBox1.Location = new System.Drawing.Point(16, 8);
> > this.listBox1.Name = "listBox1";
> > this.listBox1.Size = new System.Drawing.Size(784, 238);
> > this.listBox1.TabIndex = 0;
> > //
> > // Form1
> > //
> > this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
> > this.ClientSize = new System.Drawing.Size(816, 266);
> > this.Controls.Add(this.listBox1);
> > this.Name = "Form1";
> > this.Text = "Form1";
> > this.Load += new System.EventHandler(this.Form1_Load);
> > this.ResumeLayout(false);
> >
> > }
> > #endregion
> >
> > [STAThread]
> > static void Main()
> > {
> > Application.Run(new Form1());
> > }
> >
> > private void Form1_Load(object sender, System.EventArgs e)
> > {
> > using (SqlConnection my_connection = new SqlConnection("server =
> > fred\\sqlexpress; database = TrialDB; Integrated Security = TRUE;"))
> > {
> > string query = "SELECT Column_one, Column_two, Column_three FROM
> > dbo.Table_1 "+
> > "SELECT Column_one, Column_two, Column_three FROM dbo.Table_2";
> >
> > using(SqlDataAdapter my_adapter = new
> > SqlDataAdapter(query,my_connection))
> > {
> >
> > using(DataSet data_set = new DataSet())
> > {
> > my_adapter.TableMappings.Add("Tab", "bdo.Table_1");
> > my_adapter.TableMappings.Add("Tab1", "bdo.Table_2");
> > my_adapter.Fill(data_set,"Tab");
> >
> > DataTable my_table = data_set.Tables["Tab"];
> >
> > string display_string = string.Empty;
> >
> > foreach(DataRow row in
> > my_table.Rows)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
> > {
> > for(int x = 0; x < 3; x++)
> > {
> > display_string += '\t' + (row.ItemArray[x].ToString());
> > }
> > listBox1.Items.Add(display_string);
> > display_string = string.Empty;
> > }
> > }
> > }
> > }
> > }
> > }
> >
> >
>
>



Re: Please help with some code. by Cor

Cor
Fri Jun 09 05:12:22 CDT 2006

Adrian,

I did mean what was the error that was given.
There could be more reasons for that (empty table etc)

Cor

"Adrian" <00@00.00> schreef in bericht
news:44893ebf$0$744$5fc3050@dreader2.news.tiscali.nl...
>> And the error is?
> That I should have looped through the tables
> as I have subsequently discovered.
> Adrian.
>
> "Cor Ligthert [MVP]" <notmyfirstname@planet.nl> wrote in message
> news:uEQdHx5iGHA.4748@TK2MSFTNGP04.phx.gbl...
>> And the error is?
>>
>> :-)
>>
>> Cor
>>
>> "Adrian" <00@00.00> schreef in bericht
>> news:448926b2$0$713$5fc3050@dreader2.news.tiscali.nl...
>> > There is an error in the line marked XXX
>> > Could someone put it right for me?
>> > Many thanks,
>> > Adrian.
>> >
>> > using System;
>> > using System.Drawing;
>> > using System.Collections;
>> > using System.ComponentModel;
>> > using System.Windows.Forms;
>> > using System.Data;
>> > using System.Data.SqlClient;
>> >
>> > namespace WindowsApplication2
>> > {
>> > public class Form1 : System.Windows.Forms.Form
>> > {
>> >
>> > #region Windows Form Designer generated code
>> > private System.Windows.Forms.ListBox listBox1;
>> > private System.ComponentModel.Container components = null;
>> > public Form1()
>> > {
>> > InitializeComponent();
>> > }
>> > protected override void Dispose( bool disposing )
>> > {
>> > if( disposing )
>> > {
>> > if (components != null)
>> > {
>> > components.Dispose();
>> > }
>> > }
>> > base.Dispose( disposing );
>> > }
>> > private void InitializeComponent()
>> > {
>> > this.listBox1 = new System.Windows.Forms.ListBox();
>> > this.SuspendLayout();
>> > //
>> > // listBox1
>> > //
>> > this.listBox1.Location = new System.Drawing.Point(16, 8);
>> > this.listBox1.Name = "listBox1";
>> > this.listBox1.Size = new System.Drawing.Size(784, 238);
>> > this.listBox1.TabIndex = 0;
>> > //
>> > // Form1
>> > //
>> > this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
>> > this.ClientSize = new System.Drawing.Size(816, 266);
>> > this.Controls.Add(this.listBox1);
>> > this.Name = "Form1";
>> > this.Text = "Form1";
>> > this.Load += new System.EventHandler(this.Form1_Load);
>> > this.ResumeLayout(false);
>> >
>> > }
>> > #endregion
>> >
>> > [STAThread]
>> > static void Main()
>> > {
>> > Application.Run(new Form1());
>> > }
>> >
>> > private void Form1_Load(object sender, System.EventArgs e)
>> > {
>> > using (SqlConnection my_connection = new SqlConnection("server =
>> > fred\\sqlexpress; database = TrialDB; Integrated Security = TRUE;"))
>> > {
>> > string query = "SELECT Column_one, Column_two, Column_three FROM
>> > dbo.Table_1 "+
>> > "SELECT Column_one, Column_two, Column_three FROM dbo.Table_2";
>> >
>> > using(SqlDataAdapter my_adapter = new
>> > SqlDataAdapter(query,my_connection))
>> > {
>> >
>> > using(DataSet data_set = new DataSet())
>> > {
>> > my_adapter.TableMappings.Add("Tab", "bdo.Table_1");
>> > my_adapter.TableMappings.Add("Tab1", "bdo.Table_2");
>> > my_adapter.Fill(data_set,"Tab");
>> >
>> > DataTable my_table = data_set.Tables["Tab"];
>> >
>> > string display_string = string.Empty;
>> >
>> > foreach(DataRow row in
>> > my_table.Rows)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>> > {
>> > for(int x = 0; x < 3; x++)
>> > {
>> > display_string += '\t' + (row.ItemArray[x].ToString());
>> > }
>> > listBox1.Items.Add(display_string);
>> > display_string = string.Empty;
>> > }
>> > }
>> > }
>> > }
>> > }
>> > }
>> >
>> >
>>
>>
>
>



Re: Please help with some code. by Adrian

Adrian
Fri Jun 09 05:50:15 CDT 2006

> I did mean what was the error that was given.
> There could be more reasons for that (empty table etc)
>
> Cor
>

This seems to work ok.
No missing table.
IMO the loop was missing.

Adrian

private void Form1_Load(object sender, System.EventArgs e)
{
using (SqlConnection my_connection = new SqlConnection("server =
fred\\sqlexpress; database = TrialDB; Integrated Security = TRUE;"))
{
string query = "SELECT Column_one, Column_two, Column_three FROM
dbo.Table_1 "+
"SELECT Column_one, Column_two, Column_three FROM dbo.Table_2" ;

using(SqlDataAdapter my_adapter = new SqlDataAdapter(query,my_connection))
{

using(DataSet data_set = new DataSet())
{
my_adapter.TableMappings.Add("Tab", "bdo.Table_1");
my_adapter.TableMappings.Add("Tab1", "bdo.Table_2");
my_adapter.Fill(data_set,"Tab");
for(int t = 0; t<2; t++)
{
DataTable my_table = data_set.Tables[t];
string display_string = string.Empty;
foreach(DataRow row in my_table.Rows)
{
for(int x = 0; x < 3; x++)
{
display_string += '\t' + (row.ItemArray[x].ToString());
}
listBox1.Items.Add(display_string);
display_string = string.Empty;
}
}
}
}
}
}