Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data access from sqlserver

Status
Not open for further replies.

achick

Programmer
May 23, 2007
66
US
I am new to VB/ASP.net

I have a login form with user data in SQL server database.

I am trying to compare the password for the username the user entered on the form with the one stored in database.

In the button click event I am trying to use the following, but I get an error.

Dim strchkpw as string

strchkpw= SqlDataSource1.SelectCommand

How can I get to run the sql command that stchchkpw has and return the value

(If I use sqldatasource1.selectparameters(txtusername.txt), I get an error)

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BMI_TestConnectionString %>"
SelectCommand="SELECT [Password] fROM [Contacts_Users] WHERE ([Username] = @Username)">
<SelectParameters>
<asp:FormParameter FormField="txtUsername" Name="Username" Type="String" />
</SelectParameters>
</asp:SqlDataSource>




 
1st problem. you are using data source controls. don't, just don't. they are the worst idea ever. you cannot debug them, you cannot test them. they promote bad programming practices. they are enticing, but completely useless.

I would go with 1 of 2 options:
1. use an established ORM for you data access needs. Nhibernate, ActiveRecord, LLBL Gen Pro, MS Data Access Block. tecnically MS DA isn't an ORM but a Dataset mapper, but I digress.
2. use the ADO.Net components to access the database.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
For this statement strchkpw= SqlDataSource1.SelectCommand
I just need to know how to execute the sql.

-----
But if I use the following command, I get build error
strpassword = SqlDataSource1.SelectParameters(txtUsername.Text) . Looks like it is expecting integer but I am providing string. How should I change that?

Error 1 Value of type 'System.Web.UI.WebControls.Parameter' cannot be converted to 'String'. C:\Documents and Settings\katterapallichaitany\My Documents\Visual Studio 2005\WebSites\testsite1\login.aspx.vb 15 23 C:\...\testsite1\
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top