28. april 2004 - 14:06
Der er
7 kommentarer og 1 løsning
Jeg får en run time error når jeg kører en dropdownlist
Jeg får en run time error når jeg kører en dropdownlist, jeg indlæser fra en database ind i et dataset. Det går fint, der er hul igennem. Når jeg så vælger en linie i dropdown'en er der fejl. er der nogen som har lyst til at se på koden, så kan jeg lige sende den op. Det er sandsynligvis kun en detalje, jeg bare har stiret mig blind på.
Annonceindlæg fra Trustworks
Tillid i en Zero-Trust verden
Med voksende trusler, nye EU-krav og øget kompleksitet er cybersikkerhed nu en central ledelsesopgave på linje med strategi og økonomi.
28. april 2004 - 14:08
#1
Show us your code :)
28. april 2004 - 14:10
#2
using System.Data.SqlClient; using System.Windows.Forms; using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace matrixwin32app { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.ComboBox DropDownList1; private System.Windows.Forms.Label Label28; private System.Windows.Forms.TextBox TextBox7; private System.Windows.Forms.Button Button2; private System.Windows.Forms.Label Label3; private System.Windows.Forms.Label Label2; private System.Windows.Forms.TextBox TextBox2; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.DropDownList1 = new System.Windows.Forms.ComboBox(); this.Label28 = new System.Windows.Forms.Label(); this.TextBox7 = new System.Windows.Forms.TextBox(); this.Button2 = new System.Windows.Forms.Button(); this.Label3 = new System.Windows.Forms.Label(); this.Label2 = new System.Windows.Forms.Label(); this.TextBox2 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // DropDownList1 // this.DropDownList1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.DropDownList1.Location = new System.Drawing.Point(24, 32); this.DropDownList1.Name = "DropDownList1"; this.DropDownList1.Size = new System.Drawing.Size(121, 21); this.DropDownList1.TabIndex = 0; this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged); // // Label28 // this.Label28.Location = new System.Drawing.Point(232, 24); this.Label28.Name = "Label28"; this.Label28.Size = new System.Drawing.Size(240, 144); this.Label28.TabIndex = 1; this.Label28.Text = "Til fejlmeddelse"; // // TextBox7 // this.TextBox7.Location = new System.Drawing.Point(24, 112); this.TextBox7.Name = "TextBox7"; this.TextBox7.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal; this.TextBox7.TabIndex = 2; this.TextBox7.Text = "textBox1"; // // Button2 // this.Button2.Location = new System.Drawing.Point(120, 280); this.Button2.Name = "Button2"; this.Button2.TabIndex = 4; this.Button2.Text = "Button2"; this.Button2.Click += new System.EventHandler(this.Button2_Click); // // Label3 // this.Label3.Location = new System.Drawing.Point(336, 240); this.Label3.Name = "Label3"; this.Label3.TabIndex = 5; this.Label3.Text = "label3"; // // Label2 // this.Label2.Location = new System.Drawing.Point(336, 208); this.Label2.Name = "Label2"; this.Label2.TabIndex = 6; this.Label2.Text = "label2"; // // TextBox2 // this.TextBox2.Location = new System.Drawing.Point(24, 160); this.TextBox2.Name = "TextBox2"; this.TextBox2.TabIndex = 7; this.TextBox2.Text = "textBox2"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(488, 334); this.Controls.Add(this.TextBox2); this.Controls.Add(this.Label2); this.Controls.Add(this.Label3); this.Controls.Add(this.Button2); this.Controls.Add(this.TextBox7); this.Controls.Add(this.Label28); this.Controls.Add(this.DropDownList1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { string cS = "provider=Microsoft.JET.OLEDB.4.0; " + "data source = C:\\Documents and Settings\\kj\\My Documents\\Visual Studio Projects\\matrixwin32app\\matrix.mdb"; string scS = "Select * from areatabel;"; DropDownList1.Items.Clear(); ListItem l = new ListItem("No area is selected", "0"); DropDownList1.Items.Add(l); try { OleDbConnection areCnx = new OleDbConnection(cS); areCnx.Open(); OleDbDataAdapter areAdapter = new OleDbDataAdapter(scS,areCnx); DataSet areDataset = new DataSet(); areAdapter.Fill(areDataset, "Area"); DataTable areDatatable = areDataset.Tables["Area"]; foreach(DataRow t in areDatatable.Rows) { string t1 = (string)t["area_navn"]; int t2 = (int)t["area_nummer"]; ListItem s = new ListItem(t1, t2.ToString()); DropDownList1.Items.Add(s); } areCnx.Close(); } catch(Exception ex) { Label28.Text = ex.ToString(); } } private void slet() { TextBox7.Text = ""; Label28.Text = ""; } private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) { Button2.Visible = true; string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source = C:\\Documents and Settings\\kj\\My Documents\\Visual Studio Projects\\matrixwin32app\\matrix.mdb"; string commandString3 = "select * from areatabel where area_nummer ="+ DropDownList1.SelectedItem+";"; Label3.Text=DropDownList1.SelectedItem.ToString(); OleDbDataAdapter dataAdapter3 = new OleDbDataAdapter (commandString3, connectionString); DataSet dataSet3 = new DataSet(); dataAdapter3.Fill(dataSet3,"area"); DataTable dataTable3 = dataSet3.Tables["area"]; foreach (DataRow dataRow in dataTable3.Rows) { Label2.Text=(dataRow["area_nummer"].ToString()); } Label3.Text=DropDownList1.SelectedItem.ToString(); } private void Button2_Click(object sender, System.EventArgs e) { } } }
28. april 2004 - 14:12
#3
i den her string viser den, den tekst der er i dropdownlisten, og ikke det tal der er hentet fra database. Hvis det kan hjælpe string commandString3 = "select * from areatabel where area_nummer ="+ DropDownList1.SelectedItem+";";
28. april 2004 - 14:22
#4
Jeg har lige besøgt dit forum dotnetforum.dk, det ser ret godt ud. jeg har tidligere spurgt om en der kunne hjælpe mig med noget kode til at login med. altså brugernavn og password. Det har du jo på din side kan du hjælpe mig med det?
28. april 2004 - 14:28
#5
Kan du finde ud af det? Ellers spørg hvis der er noget du er i tvivl om!!
28. april 2004 - 14:36
#6
Hvis du er igang, eller ikke er igang kan du så ikke lige sige det så jeg ikke sidder og venter!!!!
28. april 2004 - 14:54
#7
Tak for hjælpen, og tak for du svarer
Ok hvor blev du af?? Lukker spm
Kurser inden for grundlæggende programmering