Last post Dec 08, 2013 01:59 PM by inspiredlearner
Dec 05, 2013 10:36 AM|inspiredlearner|LINK
Im currently trying to build a website in Visual Studio 2013. I have a database with tables in mssql. One of those tables has a sql bit ("true"/"false") type. I dont know how to count how many true columns there are and disply them in visul studio. I just
want to display the total figure not the actual column.
I also have created a verification so that users may log on to my web applictaion (not using the pre installed login control). I dont know how to I create personal accounts from here so each user that logs in has there own area with their information on
it. ie Display there name on login eg Welcom Roscoe J. Also so they can see there own history etc. How would I create member accounts do this in mssql (how) or visual studio (how?).
Pretty please could you be specific as I have read lots and still not understood it. Basically for the final I wanted to have created a live car park booking system. The true or false above displays how many parking space are left etc. If any one knows where
I could find similar examples or help at all I would be entirely grateful.
Thank you in advance. From a desperate learner. Ps. I am coding in C# asp.net webforms.
Dec 05, 2013 11:26 AM|Rion Williams|LINK
If you had a table that provided the number of parking spaces that were occupied, you could actually use a simple COUNT statement to determine the number of available or unavailable rows :
SELECT COUNT(*) As AvailableSpaces
WHERE IsOccupied = 0
or you could simply grab all of the columns that have the "IsOccupied" property set to true (or false depending on what you need) :
WHERE IsOccupied = 0
An example might look like the following :
using(OdbcConnection mySqlConnection = new OdbcConnection("Your Connection String"))
//Open your Connection
//Build your statement
string sql = "SELECT COUNT(*) AS AvailableSpaces FROM YourTable WHERE IsOccupied = 0";
//Build a command to execute
OdbcCommand mySqlCommand = new OdbcCommand(sql,mySqlConnection);
//This will yield the number of rows
int availableSpaces = mySqlCommand.ExecuteScalar();
//Output the number of spaces in your TextBox
YourAvailableSpacesTextBox.Text = availableSpaces.ToString();
Dec 08, 2013 01:59 PM|inspiredlearner|LINK
Thank you for this. Yes I do have a column to define the spaces I have done this as bits so its true/false is this a diffucult way to do it. My table is as below: The one i need to count is clDisbaled which is type: BIT. My SQL merely has tables and no queries
or functions in it as I am not sure if I do the quieries in SQL or Visua studio using ASP.net.
my login I have the table as below:
code I have done to verify a user is below but I cant crete personal pages from this it merely allows users access to the site but I cant do anything like personalise or call related information from the databese. I woul dbe grateful for any hellp or information
this is the up front code :
this is the code behing it: Welcome.aspx.cs
sds = new
* FROM [tbStaff] WHERE [staffUser] = @Username1 AND [staffPswd] = @Password1";
dv = (DataView)sds.Select(DataSourceSelectArguments.Empty);
(dv.Count == 0)
username and password!";
conn = new
sql = "INSERT
INTO tbStaff (staffUser, staffPswd) VALUES "
cmd = new
pram = new
pram.Value = Username1;
pram.Value = Password1;
i = 0; i < pram.Length; i++)
msg = "Error
occured while inserting";
msg += ex_msg.Message;