Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 22nd, 2005, 07:24 AM
Registered User
 
Join Date: Oct 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default data source and SQL queries

Hey everyone,

I have been trying to retrieve data from my SQL Server database to allow the user to view his own info using data source, however when i add a where clause in the SQL select query I get an error msg.

here's my method and error message:
string u = Home.username; //this is a global string variable created in the Home.aspx file specifying the name of the user currently logged on
string myConnection = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn2 = new SqlConnection(myConnection);
string sql="SELECT* FROM LogIn where (username=u)"; //the where clause here isnt accepted
SqlDataAdapter myCommand = new SqlDataAdapter(sql, conn2);


DataSet ds = new DataSet();
myCommand.Fill(ds);
DataView source = new DataView(ds.Tables[0]);
MyDataGrid.DataSource = source ;
MyDataGrid.DataBind();
}

Error:

Server Error in '/WhatsYourWebsite' Application.
--------------------------------------------------------------------------------

Invalid column name 'u'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'u'.

Source Error:


Line 96: // Create and fill a DataSet.
Line 97: DataSet ds = new DataSet();
Line 98: myCommand.Fill(ds);
Line 99: // Bind MyDataGrid to the DataSet. MyDataGrid is the ID for the
Line 100: // DataGrid control in the HTML section.


Source File: c:\inetpub\wwwroot\whatsyourwebsite\main.aspx.cs Line: 98

Stack Trace:


[SqlException: Invalid column name 'u'.]
System.Data.SqlClient.SqlCommand.ExecuteRead er(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.SqlClient.SqlCommand.ExecuteRead er(CommandBehavior behavior) +44
System.Data.SqlClient.SqlCommand.System.Data .IDbCommand.ExecuteReader(CommandBehavior behavior) +5
System.Data.Common.DbDataAdapter.FillFromCom mand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSe t dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSe t dataSet) +38
WhatsYourWebsite.main.Button2_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\whatsyourwebsite\main.aspx.cs:9 8
System.Web.UI.WebControls.Button.OnClick(Eve ntArgs e) +108
System.Web.UI.WebControls.Button.System.Web. UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostB ackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameVa lueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277


I would appreciate some help
Thanks
Susan
 
Old October 24th, 2005, 01:13 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

string sql="SELECT* FROM LogIn where username= " + u;






Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Source Tools to generate XML from SQL data ethanhunt XML 0 May 7th, 2008 02:55 PM
Dynamic sql data source MDM ASP.NET 2.0 Professional 3 April 5th, 2006 11:45 PM
Anyone Expert in SQL Queries itHighway Classic ASP Basics 2 May 24th, 2005 03:37 AM
pls help SQL Queries sush_blr SQL Server 2000 2 February 1st, 2005 01:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.