title image


Smiley SqlDataReader
Guten Abend



Ich habe folgende ASP.NET Seite jedoch erhalte ich immer eine Exception:

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Configuration;

using System.Data.SqlClient;



namespace WebApplication1

{

///

/// Zusammenfassung für Benutzerverwaltung.

///

public class Benutzerverwaltung2 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Button btUpdate;

protected System.Web.UI.WebControls.Label ErrorMessage;

protected System.Web.UI.WebControls.DataGrid DataGridUser;

private static DataSet ds = null;

protected System.Web.UI.WebControls.Label Label1;

protected System.Web.UI.WebControls.Label Label2;

private static SqlConnection myConn = null;

private static DataView CartView = null;

private static SqlDataReader dr = null;

private static SqlCommand myComm = null;





DataTable Cart

{

get

{

/*if (Session["DGC_ShoppingCart"] == null)

{*/

DataTable tmpCart = new DataTable();

tmpCart.Columns.Add(new DataColumn("Nickname", typeof(string)));

tmpCart.Columns.Add(new DataColumn("Passwort", typeof(string)));

tmpCart.Columns.Add(new DataColumn("EMail", typeof(string)));

tmpCart.Columns.Add(new DataColumn("Multi", typeof(bool)));

tmpCart.Columns.Add(new DataColumn("Tool", typeof(int)));

tmpCart.Columns.Add(new DataColumn("GalaxieAbk", typeof(string)));

Session["DGC_ShoppingCart"] = tmpCart;



while (dr.Read() == true)

{

DataRow ds = tmpCart.NewRow();

ds[0] = dr.GetString(0).Trim();

ds[1] = dr.GetString(1).Trim();

ds[2] = dr.GetString(2).Trim();

ds[4] = dr.GetBoolean(3);

ds[5] = dr.GetInt16(4);

ds[6] = dr.GetString(5).Trim();

tmpCart.Rows.Add(ds);

dr.Read();

}

return tmpCart;

/*}

else

return (DataTable)Session["DGC_ShoppingCart"];*/

}

}



void BindGrid()

{

DataGridUser.DataSource = CartView;

DataGridUser.DataBind();

}



void Page_Init(Object sender, EventArgs e)

{

DataGridUser.EnableViewState=true;

}



private void Page_Load(object sender, System.EventArgs e)

{

string connstr = ConfigurationSettings.AppSettings["DBUser"];

HttpCookieCollection cookies = Request.Cookies;

string galaxy = cookies["stargameu"].Value;

string cmdstr = null;

if (galaxy == "admin")

{

cmdstr = "SELECT Nickname, Passwort, Email, Multi, tool, GalaxieAbk FROM Benutzer ORDER BY Nickname";

}

else

{

cmdstr = "SELECT Nickname, Passwort, Email, Multi, tool, GalaxieAbk FROM Benutzer WHERE GalaxieAbk = '" + galaxy + "' ORDER BY Nickname";

}

myConn = new SqlConnection(connstr);

myComm = new SqlCommand(cmdstr, myConn);



try

{

myConn.Open();

dr = myComm.ExecuteReader();

/*ds = new DataSet();

da.Fill(ds);

DataGridUser.DataSource = ds.Tables[0];

DataGridUser.DataBind();*/

CartView = Cart.DefaultView;

BindGrid();

}

catch(Exception myException)

{

ErrorMessage.Text = "Oops. The error: " + myException.ToString();

ErrorMessage.Text += "" + cmdstr;

ErrorMessage.Visible = true;

}

finally

{

dr.Close();

myConn.Close();

}

}



#region Vom Web Form-Designer generierter Code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: Dieser Aufruf ist für den ASP.NET Web Form-Designer erforderlich.

//

InitializeComponent();

base.OnInit(e);

}



///

/// Erforderliche Methode für die Designerunterstützung.

/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.

///

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);



}

#endregion



public void btUpdate_Click(object sender, System.EventArgs e)

{



}

}

}



Exception:

Oops. The error: System.InvalidOperationException: Die ConnectionString-Eigenschaft wurde nicht initialisiert. at System.Data.SqlClient.SqlConnection.Open() at WebApplication1.planet.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication1\planet.aspx.cs:line 84

SELECT ID, Sonnensystem, Koordinate, Nickname, Name FROM Sonnensysteme ORDER BY Name



Gehe ich mit dem SqlDataReader nicht richtig um, oder was habe ich vergessen?

Danke
my Page
my Weblog

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: