If Statement combined with SQL statement.


 This is going to sound like quite  a strange question. Basically what I am trying to do is use Membership.GetUser().UserName to get the current user who is logged in and I want to see if that user exists in a table on my database before adding some data to the labels. I figured it should go in the page load part. The name of the table is userteams.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

If Membership.GetUser().UserName exists in Userteams Then goallie.Text = Select player FROM Userteams Where Username = Membership.getUser().UserName.

End Sub


The part I put in bold and italic is made up but I need to find some sort of way of making that into code and also combining the SQL statement and If Statement. Also another problem I envisage is that the sql statement will not simply work as its from an access database. I would appreciate any help.

 Many Thanks

2/18/2008 7:11:08 PM
asp.net.access-datasource 4679 articles. 0 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 40

what you want to do is make a stored procedure in your database that takes in the username, (or id) then it does a select like yours and returns a value or not, then in your code you make a sqlcommand using the system.sqldataclient (if youre using sql) to make a command and fire it

ConnectionStringSettings conStr;
        conStr = ConfigurationManager.ConnectionStrings["IPSplitConnectionString"];
        SqlConnection conn = new SqlConnection(conStr.ConnectionString);
        SqlCommand command = new SqlCommand(procedure, conn);
(your procedure sproc could have something like this in it, select count(player) from userteams where username = @username)
        command.CommandType = CommandType.StoredProcedure;


will return your value


thenyou can do something like   



the user is in your table

my friends call me MOI
2/18/2008 7:27:41 PM



Thanks for replying. So far with your help I have

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

ConnectionStringSettings conStr;

conStr = ConfigurationManager.ConnectionStrings["IPSplitConnectionString"];

SqlConnection conn = new SqlConnection(conStr.ConnectionString);SqlCommand command = new SqlCommand(select count(player) from userteams where username = "membership.getuser().username", conn);

command.CommandType = CommandType.StoredProcedure;



If (Command.executescalar() > 0) Then

goallie.Text = Select player FROM Userteams Where Username = Membership.getUser().UserName.


End If


End Sub


I have got like 10 errors though, do you know what I am doing wrong.

2/18/2008 8:58:55 PM

Maybe does anyone else have any ideas on how to tackle this problem? I've tried a few things today with no success.

2/19/2008 9:30:36 PM

Ok no worries I finally figured it out. Thanks for the help

2/20/2008 6:08:37 PM

Similar Artilces:

SQL statement and If statement
I've problem, it's in sqlcommand it's in "where" condition, which if it's exist in sql the "ELSE" not work, and if the condition not in sqlcommand the "ELSE" appear, could someone help  it's in selectcommand.CommandText = "SELECT Weekno FROM Weeks where Weekno='" + Weekno.Text + "'" if i delete the condition the " ELSE " appear. otherwise it's not appear whole code Dim myconnection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\football.mdf;Integrated S...

combining 2 sql statements using Access version and not sql server to show results in a data list
Hi, I have 2 sql statements which will run in Access: private string m_cmdInitial = "Select Distinct Mid([Attribute Name],1,1) AS Initial FROM [Attributes]";  private string m_cmdCustmrs = "SELECT * FROM [Attributes] WHERE(Attributes.[Attribute Name]) LIKE '{0}*'"; The thing is that using SQL server the two sql statements can be combined using the format Function of ASP.net just by putting semicolon between the statements. The purpose is as follows: I am using 2 data lists. The first one is just a list of letters on top from which the user can choose a letter on which the term starts...

Adding an IF Statement to the SQL Statement
I have the following tables and SQL statment which works out a league table for me from the given results. I am now trying to add a bit more to this: If the Walkover column = 1 then that row will be a home walkover meaning that the score will be 0(Home Score) - 0(Away Score) but the home team will recieve 3 points, and away team recieves 0 points, win column will be 1 and the played colum will be 1 as well.If the Walkover column = 2 then that row will be a home walkover meaning that the score will be 0(Home Score) - 0(Away Score) but the away team will recieve 3 po...

gridview, access datasource, dynamic assignment sql statement
I have a gridview "gvTable" and a datasource "accessdatasource1".When I load the page all the data from the table "Models" is displayed.When I click the Categories button I want to have the gridview display the rows from my "Categories" table (which contains columns: ID and CategoryName), on pages of each 5 rows in length.It does display all the info in the right amount of rows.HOWEVER: when I click on the next page or column header to sort I get the error:"System.IndexOutOfRangeException: Cannot find column CategoryName"Here's all my code: <asp:GridView ID="gvTable" runat="server" Allow...

Viewing a SPIDs last SQL statement using sqltext()...though sometimes only partial SQL statements are shown
The dbcc sqltext() command seems to allow you to view the last SQL statement issued by an active SPID on the server. However I've noticed that sometimes only part of the SQL statement is returned - does anyone know why this might be, and if so whether it's due to a server configuration. Anyway, here's my notes on how to view the last SQL statement processed: ** How to see the last SQL a SPID has processed -- dbcc traceon(3604) Directs trace output to the client, rather than to the error log 1> dbcc traceon(3604) 2> go DBCC execution completed. If DBCC pr...

sql statement datename and not in equivalent to linq statement
Hi,     How can I translate this sql syntax statement to a linq to sql codes?? I like to separate records that are in first group, monday to saturday but date not in holidays table, and in second group, either sunday or date in holidays table...  /*Sql statement */ /*Mon to Sat group and not a holiday*/ Select * From Deliveries where DateName(dw,DeliveryDate) != 'Sunday' and DeliveryDate Not In (Select Date From Holidays) /*Sun & holiday group*/ Select * From Deliveries where DateName(dw,DeliveryDate) = 'Sunday' or DeliveryDat...

Please Help me:SQL statement failed: (-301) Internal database error ??? -- transaction rolled back SQL statement failed: (-101) Not connected to a database
Hi all, I am using Adaptive Server Anywhere 8 version I am able to sync successfully between 2 desktops with the same version. When I am trying to sync with my pocket pc device version 8.0.4122, Towards the end of Synchronization (nearly 95% completed) ,I am getting this error "E. 05/29 19:28:31. SQL statement failed: (-301) Internal database error ??? -- transaction rolled back E. 05/29 19:28:31. SQL statement failed: (-101) Not connected to a database" The log file contains E. 05/29 19:28:31. SQL statement failed: (-301) Internal database er...

Dynamic SQL delete statement not supported by select statement
while trying to update my data through code i am getting "Dynamic SQL delete statement not supported by select statement which doesnt return any key value" error.I am wondering what is wrong and where Could you please elaborate more on the scenario that you are trying to delete ie. post some code.Mohammad Musa, Bangladesh...

Sql Datasource select statement
I have a gridview that uses a sqldatasource to display (classid, userid, startdate, enddate) from a class table.  My datagrid also contains a submit button.  When this button is clicked I am inserting this data into a new table called register.  I need a way to not show classes for the user if that user is already in the register table for that class.  Currently all items are being shown which would allow the user to register for the same class more than once.  Any ideas?   Thanks  you could make classid and userid as a pri...

Top Statement and INDEX= Statement in Datawindow SQL Painter
Hi, Is there any way to put TOP and INDEX statement into Sql definition in Datawindow painter in graphical view. I know that I can go to "Convert to Sytax" but I want to learn if there is an option like "DISTINCT" in painter. SQL Example: Select TOP 100 Name,Surname FROM Names (INDEX = INX_name) Thanks for all Ali 'Top 100' you can do by making the first item in the select list a computed column TOP 100 Name I can't think of a way of doing Index. I never use graphical mode for anything other than very simple queries (and usually no...

String with statements to Concatenation with select statement and execute that statement
Hi I have variable @str='%dataset% or Question like %DataReader%' to concatenate with Select *from Question where Question like @str Here is one of the Column Name Question use something like this (But do remember you have SQL Injection threat with this kind of approach.) CREATE PROCEDURE <<NAME>> @str as varchar(500) AS declare @strQuery as varchar(1000) set @strQuery = 'SELECT * FROM Question WHERE ' + @str execute(@strQuery) to run this, it would have to be like this  exec ('Select * from Question where Question like &#...

RE: SQL::Statement cannot parse valid Postgresql statement
> From: Terrence Brannon [mailto:metaperl@mac.com] > > On Monday, December 10, 2001, at 09:16 AM, Jeff Zucker wrote: > > > Terrence Brannon wrote: > >> > >> The following SQL is not parseable by SQL::Statement: > >> > >> INSERT > >> INTO thot_log (thot_fk,thot_type_fk,thot_temporality_fk,date) > >> VALUES (?,?,?,CURRENT_TIMESTAMP) > > What I have is a program which reads a SQL statement from a file. > It parses it with SQL::Statement, then it prepares this > statement, then does an ...

help with access
hi. i have the code: Dim objConnection As OleDbConnection  Dim objCommand As OleDbCommand  Dim objDataReader As OleDbDataReader  Dim strSQLQuery As String    objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\database\database.mdb;")   if rblLTorGT.SelectedValue = "Id" then   lblSQLCommandLabel.Text = session("session_name")  strSQLQuery = "SELECT id,name,age,sum, address       FROM sales &qu...

sql statement in vb.net
hi there, i've a question about building an sql-statement in vb.net. the statement i tried in the sql server , there is everything ok. sql: EXEC crosstab 'select KategorieB from Planungsdaten group by Kategorie ', 'sum(PDAnzahl)', 'PerDatum', 'Planungsdaten', 'Planung = 8 and Periode in (select Periode from getperiodenplanung(8))' now how can i put this into my vb-code?? i tried it the same way like in sqlserver but i got an error : error: "wrong syntax near the END Keyword" please help thanks Patrick ...

Web resources about - If Statement combined with SQL statement. - asp.net.access-datasource

User:Jimbo Wales/Statement of principles - Wikipedia, the free encyclopedia
As we move forward with software and social changes, I think it is imperative that I state clearly and forcefully my views on openness and the ...

Category:Articles containing potentially dated statements from July 2011 - Wikipedia, the free encyclopedia ...
This is an administration category . It is used for administration of the Wikipedia project and is not part of the encyclopedia. It contains ...

David Bowie: Private ceremony planned as family issues statement thanking fans
LONDON, Jan 14 Reuters - David Bowie will be remembered in a private ceremony, says his family, who have thanked fans for their support after ...

Tamir Rice's Mother Comments on LeBron James Not Giving Statement on Son's Death - Bleacher Report
One week after Cleveland Cavaliers superstar LeBron James made careful comments regarding the death of Tamir Rice, the boy's mother spoke out ...

Mayor Martin Walsh’s statement on Obama gun control initiatives
Mayor Martin Walsh was in Washington, D.C. today during President Obama’s remarks on gun violence. Below is a statement from Mayor Martin Walsh, ...

David Bowie’s family’s statement: ceremony will be private, no official memorial
... has been cremated and that he didn’t want to have a big funeral, he just wanted us to remember him by his music. His family has issued a statement ...

Chipotle sued over food safety statements
Chipotle Mexican Grill was sued for allegedly misleading investors about its food safety controls.

National Shooting Sports Foundation Statement Regarding The New Executive Order On Guns
National Shooting Sports Foundation Statement Regarding The New Executive Order On Guns

Wheaton College moving to fire professor after Muslim statements
Wheaton College leaders are taking steps to fire the suspended political science professor who drew fire late last year for saying Christians ...

Business on Display: Making a Statement with Digital Signage
The digital signage market is projected to be worth $22 billion by 2020. Join us for our first of four webinars powered by Samsung as we discuss ...

Resources last updated: 1/16/2016 9:39:52 AM