Showing posts with label username. Show all posts
Showing posts with label username. Show all posts

Wednesday, March 28, 2012

How do i ?! Basic Select Statement

I have an sql data source..select command is something like this.

Select password from users where username = Username.Text

how can i retrieve the password value and save it into a string?! to make a comparison between password value and a textbox Password.Text

i know its a silly question but i took me long time and i still can't find the ans

We are going to need a little more context to evaluate your exact situation, and how to do what you ask, but here's 1 method:

Dim sqlConn as new SqlConnection("connection string here")

Dim sqlCmd as new SqlCommand("SELECT password from users where username = @.username", SqlConn)

sqlCmd.Paramaters.AddwithValue("@.username", username.text)

Dim DA as new SqlDataAdapter(SqlCmd)

Dim DT as new DataTable

DA.Fill(DT)

Dim myString as string = DT.rows(0).item("password").value ' This line may not be totally correct, doing it from memory and will edit it later

If myString.tolower = stringToCompare.tolower then

'Password is valid

else

'Password could be valid - but something threw you into the else statment, maybe an empty string.

end if

|||

Connection string and select command are already defined in the SqlDataSource.

how can you use the SqlDataSource to extract the value of the password?

i tried to use a hidden GridView but i didn't know how to access a specific cell

by the way i am using C#

|||

The above example is a much cleaner method of getting information like this. Putting a hidden gridview on your page is a VERY heavy method of trying to extract a single value, but it can be done.

Please see this article on how to extract a Datatable from the SqlDataSource control. Once you've done that, you can access a specific row of your datatable as mentioned above.

http://msmvps.com/blogs/egoldin/archive/2006/12/27/how-to-get-datatable-out-of-sqldatasource.aspx

I really have to recomend against this method though. If you insist on using the SqlDataSouce control to get this done, consider putting two hidden textbox on the page, and binding the value that comes back from the database to the hidden textbox, then use a compare validator and only let the user continue if page.isvalid.

How do i ?! Basic Select Statement

I have an sql data source..select command is something like this.

Select password from users where username = Username.Text

how can i retrieve the password value and save it into a string?!

to make a comparison between password value and a textbox Password.Text

i know its a silly question but i took me long time and i still can't find the answer

Hello Ahmad,

Here's some code that should help you out... I'd be happy to clarify anything if needed.

using System.Data;

using System.Data.SqlClient;

string userPassword;

string userName;

SqlConnection cnn = new SqlConnection("Data Source = (local); Initial Catalog = nameofdatabase; Integrated Security = True");

SqlCommand cmd = new SqlCommand("select Password From Users Where username = @.username", cnn);

SqlParameter UserName = new SqlParameter("@.username", userName);

cmd.Parameters.Add(UserName);

cnn.Open();

string password = (string)cmd.ExecuteScalar();

cnn.Close();

cnn.Dispose();

if (userPassword == password)

{

// success! Do something here

}

else

{

// Failure...

}

Regards.

sql

Friday, March 9, 2012

How can User add order from only one company at a time

tblUser
--
UserID uniqueidentifier PK (newid)
UserName varchar(MAX)

tblCompany
-
CompanyID uniqueidentifier PK newid()
CompanyName varchar(MAX)

tblUserCart
--
CompanyID uniqueidentifier FK newid()
UserID uniqueidentifier PK
Product varchar(MAX)

Asume we got 3 tables like above. Relation ship is clear: tbluser ->tblUserCart--<tblCompany

What i want is , if user gives an order from a company , sql 2005 will decline the orders from other Companies. Naturally Orders are stored in the tblUserCart table. For example, if user Arnold gives an order of CuttingTool from Company named T3 , Arnold will not be able to give another order from other than T3. I hope im clear about situation.

Happy Coding...

Do you have an application that sits on top of the database so that the tables are populated via the application? If so, that's where I'd perform your logic, rather than trying to build some trigger-based/stored procedure solution in SQL Server.|||I agree.

I would use various SELECT functions within your application to validate weather Arnold could place another order.

So, adding an order for a particular user, query the UserCart table for that user. If an order exists for that user, then flag the app user or only show products from company T3

We could write this as a procedure, put lets put the client back into Client / Server |||So answer is , do it on application. Thanks for answers.

Friday, February 24, 2012

How can I use Profile.UserName as a parameter in a SqlDataSource

I have looked and tried with no luck on using the Profile.UserName in an SQLDataSource Update select statement. and anyone please help me with this?

UpdateCommand="UPDATE tblDocumentsSET DocumentTypeID = @.DocumentTypeID, DocDescription = @.DocDescription, DocLocation = @.DocLocation, DocStartDate = @.DocStartDate, DocEndDate = @.DocEndDate, LastUpdate =GETDATE(), LastUpdateBy = @.ProfileUserWHERE (DocumentID = @.DocumentID)"
 <UpdateParameters> <asp:Parameter Name="DocumentID" /> <asp:Parameter Name="DocumentTypeID" /> <asp:Parameter Name="DocDescription" /> <asp:Parameter Name="DocLocation" /> <asp:Parameter Name="DocStartDate" /> <asp:Parameter Name="DocEndDate" /> <asp:Parameter Name="ClientID" /> <asp:Parameter Name="ProfileUser" /> </UpdateParameters>

Hi,

you should be able to use the <asp:ProfileParameter>.

Grz, Kris.

|||Thank You Very Much!