A
Adrian
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;
}
}
}
}
}
}
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;
}
}
}
}
}
}