|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
What is wrong with this code?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; } } } } } } } Adrian (00@00.00) writes:
> Coud someone please tell me what is wrong at the line marked xxxxxx ? Is this a quiz or something? What prize do I win?Seriously, if your program does not expect as you had indended, please state what the problem is. Does not compile? Does it crash when you run it? Do you get an incorrect result? Furthermore, I would guess that you get better response in microsoft.public.dotnet.framework.adonet. Most people here only ADO .Net left-hand. -- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx What prize do I win?
f.a. Show quote "Erland Sommarskog" <esq***@sommarskog.se> wrote in message news:Xns97DD5EBC26DB8Yazorman@127.0.0.1... > Adrian (00@00.00) writes: > > Coud someone please tell me what is wrong at the line marked xxxxxx ? > > Is this a quiz or something? What prize do I win? > > Seriously, if your program does not expect as you had indended, please > state what the problem is. Does not compile? Does it crash when you run it? > Do you get an incorrect result? > > Furthermore, I would guess that you get better response in > microsoft.public.dotnet.framework.adonet. Most people here only ADO .Net > left-hand. > > > -- > Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se > > Books Online for SQL Server 2005 at > http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx > Books Online for SQL Server 2000 at > http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx By "f.a." I'm sure you mean "Football Association" rather than anything
rude...don't you? Is my_table null at this point? Are you sure the "DataTable my_table = data_set.Tables..." assigns a valid value to my_table and data_set.Tables... doesn't return null? Surely debugging this would be easier by stepping through the code with a debugger (like VS for example) inspecting local variables as you go... Show quote >What prize do I win? >f.a. > >"Erland Sommarskog" <esq***@sommarskog.se> wrote in message >news:Xns97DD5EBC26DB8Yazorman@127.0.0.1... > > >>Adrian (00@00.00) writes: >> >> >>>Coud someone please tell me what is wrong at the line marked xxxxxx ? >>> >>> >>Is this a quiz or something? What prize do I win? >> >>Seriously, if your program does not expect as you had indended, please >>state what the problem is. Does not compile? Does it crash when you run >> >> >it? > > >>Do you get an incorrect result? >> >>Furthermore, I would guess that you get better response in >>microsoft.public.dotnet.framework.adonet. Most people here only ADO .Net >>left-hand. >> >> >>-- >>Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se >> >>Books Online for SQL Server 2005 at >>http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx >>Books Online for SQL Server 2000 at >>http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx >> >> > > > > This appears to be the solution
Adrian 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; } Is my_table null at this point? Are you sure the "DataTable my_table = data_set.Tables..." assigns a valid value to my_table and data_set.Tables... doesn't return null? Surely debugging this would be easier by stepping through the code with a debugger (like VS for example) inspecting local variables as you go... -- mike hodgson |
|||||||||||||||||||||||