|
when I load up the program and open the login form, I input the username and password no error pops up just the messagebox, that says invalid entry, but the information i entered is the exact same information I put into the database itself. i am thinking my problem lies within the if statement but i could be wrong
if (dt.Rows.Count > 0)
{
MessageBox.Show("Welcome");
}
else
{
MessageBox.Show("Invalid Entry");
}
i should be getting the messagebox that states Welcome, but im not.
|
|
|
|
|
Try using this
string str = "select count(*)from Login where username='"+ tbUsername + "' and password='"+ mtbPassword +"'");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(str, conn);
conn.Open();
int rows = cmd.ExecuteScalar();
if (row > 0)
{
MessageBox.Show"Welcome");
}
else
{
MessageBox.Show("Invalid Entry");
}
conn.Close();
|
|
|
|
|
i get the following error when trying to run the program
Error 1 Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?)
|
|
|
|
|
Ofcourse you have to cast it to int, i missed it and you too.
int row = Convert.ToInt32(cmd.ExecuteScalar());
|
|
|
|
|
lol yeah i just converted it then seen your reply, ok the program runs now with no errors
but i still get the Invalid Entry MessageBox when inputting the username and password, i even added a new entry to the database and still get the same thing =/ .. this has had be stumped for the past few days
|
|
|
|
|
Trace the program, see what is the value of "str" before executing the command.
|
|
|
|
|
I looked at it, the str is the string for
SELECT username,password FROM Login WHERE username='" + tbUsername + "' and password='" + mtbPassword + "'"
i removed the string for this and put it directly into the cmd section...
System.Data.SqlClient.SqlCommand cmd;
cmd = new System.Data.SqlClient.SqlCommand("SELECT username,password FROM Login WHERE username='" + tbUsername + "' and password='" + mtbPassword + "'", conn);
still not having any luck getting it to work.
thank you for time
|
|
|
|
|
I said you to see the value of "str" after tbUsername & mtbPassword is binding with it.
Maybe something is wrong with those values.
|
|
|
|
|
Just set a break point after the SELECT query is constructed. When it breaks at that point, copy the value of the string out and paste it somewhere else to execute the query to see the result. You may figure out the problem that way.
|
|
|
|
|
I too think this is the way to go.
Step 1:
First you have to make sure the connection string is correct.
Try this.
string str = ("SELECT username,password FROM dbo.Login ");<br />
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(str, conn); <br />
conn.Open(); <br />
DataTable dt = new DataTable(); System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);<br />
da.Fill(dt);
then debug and see if the da has all details from the database table.
Step 2:
If step 1 was successful, use your program, debug and see what is the value of str just before the query is fired. Execute that query directly from Query Analyzer and verify the results.
|
|
|
|
|
ok with that i get an error due to no connection string so i add in
conn.ConnectionString = "Data Source=KADAEN-PC\\SQLEXPRESS;Initial Catalog=EasyStorePro;Persist Security Info=True;User ID=********;Password=***********";
and it runs i think my main problem is in the if statment section, more or less getting the textbox to verify itself with the information in the database
so something like
password is equal to mtbPassword.Text
|
|
|
|
|
I have the following code to update the account number in the account summary & clients tables when creating a new client profile but I have a major problem now with existing records as the account concept was proposed lately.. I want to know how can I use the same code to loop through all existing (already created) records and define an account number for it?
note: I want a random weekday and dayofyear so not all records will have the same weekday creation..
INSERT INTO clients (company_id, client_name, client_cpr, client_passport, client_gender, client_nationality, client_date_of_birth, client_visa_number, client_visa_expiry, client_workpermit_number, client_workpermit_expiry, client_telephone, client_fax, client_mobile, send_sms, client_occupation, client_email, send_emails, client_salary, home_country_address, client_is_vip, client_is_blacklist) VALUES (@company_id, @client_name, @client_cpr, @client_passport, @client_gender, @client_nationality, @client_date_of_birth, @client_visa_number, @client_visa_expiry, @client_workpermit_number, @client_workpermit_expiry, @client_telephone, @client_fax, @client_mobile, @send_sms, @client_occupation, @client_email, @send_emails, @client_salary, @home_country_address, @client_is_vip, @client_is_blacklist)
SET @record_identity = SCOPE_IDENTITY()
INSERT INTO accounts_summary (client_category, client_id, cr_cpr_number, account_number, account_name) VALUES ('I', @record_identity, @client_cpr, SCOPE_IDENTITY(), @client_name)
SET @account_number_string = RIGHT('0' + convert(varchar(1), DATEPART(WEEKDAY, GETDATE())), 1)
SET @account_number_string = @account_number_string + RIGHT('000' + convert(varchar(3), DATEPART(DAYOFYEAR, GETDATE())), 3)
SET @account_number_string = @account_number_string + RIGHT('0000000' + convert(varchar(7), SCOPE_IDENTITY()), 7)
SET @account_number = convert(bigint, @account_number_string)
UPDATE accounts_summary SET account_number = @account_number WHERE account_id = SCOPE_IDENTITY()
UPDATE clients SET account_number = @account_number WHERE client_id = @record_identity
|
|
|
|
|
A note,
No one will even look at this question until you edit the sql so that it fits within the page.
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
I tried this code but it's looping forever and adding the first record from the clients into the accounts_summary thougsands of times.. why?
USE takhlees
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET NOCOUNT ON
DELETE FROM accounts_summary
-- reset primary key
INSERT INTO accounts_summary (account_number, account_name, core_account, is_read_only) VALUES (10000000001, 'CASH', 'True', 'True')
INSERT INTO accounts_summary (account_number, account_name, core_account, is_read_only) VALUES (10000000002, 'ACCOUNTS RECEIVABLE', 'True', 'True')
DECLARE @client_id int, @client_cpr varchar(50), @client_name varchar(255), @account_number_string VARCHAR(50), @account_number numeric(38,0)
DECLARE account_numbers CURSOR FOR
SELECT clients.client_id, clients.client_cpr, clients.client_name
FROM clients
ORDER BY clients.client_name
OPEN account_numbers
FETCH NEXT FROM account_numbers INTO @client_id, @client_cpr, @client_name
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO accounts_summary (client_category, client_id, cr_cpr_number, account_number, account_name) VALUES ('I', @client_id, @client_cpr, SCOPE_IDENTITY(), @client_name)
-- get random from 1 to 7
SET @account_number_string = RIGHT('0' + convert(varchar(1), DATEPART(WEEKDAY, GETDATE())), 1)
-- get random from 1 to 365
SET @account_number_string = @account_number_string + RIGHT('000' + convert(varchar(3), DATEPART(DAYOFYEAR, GETDATE())), 3)
SET @account_number_string = @account_number_string + RIGHT('0000000' + convert(varchar(7), SCOPE_IDENTITY()), 7)
SET @account_number = convert(bigint, @account_number_string)
UPDATE accounts_summary SET account_number = @account_number WHERE account_id = SCOPE_IDENTITY()
UPDATE clients SET account_number = @account_number WHERE client_id = @client_id
FETCH NEXT FROM account_numbers INTO @client_id, @client_cpr, @client_name
END
CLOSE account_numbers
DEALLOCATE account_numbers
|
|
|
|
|
Hi,
I want to use SQL Server's "Query Editor" in my C# project, can i integrate it in C# Project.
Thanks,
Sonia
modified on Wednesday, December 30, 2009 5:34 AM
|
|
|
|
|
I want to open a password protected database in vc 6 program but it do not works following is the code (if db has no password then every thing works fine)
m_pConnDB->Open (_bstr_t ("Provider=Microsoft.Jet.OLEDB.4.0; \
Data Source = Database1.accdb"), \
_bstr_t (""), \
_bstr_t (""), \
adModeUnknown);
I have also tried "Jet OLEDB:Database Password = mypassword" but it dont work
I have also tried same code on MDB file instead of accdb files but still same error.
Thanks in advance
|
|
|
|
|
pc_dev wrote: I have also tried "Jet OLEDB:Database Password = mypassword" but it dont work
Probably the wrong format for the password-argument, see connectionstrings.com[^]. I expect something like this would work;
_bstr_t ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = Database1.accdb;User Id=admin;Password=blabla;")
I are Troll
|
|
|
|
|
|
Hello guys,
I am creating a database script and in this script i am declareing a datetime variable like below
DECLARE @ENDDATE DATETIME
Now my question is that i want to initialize the value of this variable
and i am doing it this way
SET @ENDATE '30/12/2009'
and this is giving me an error saying that i cannot covert from char to datetime. How can this be done guys?
Thank you in advance
Regards,
Christian Pace
|
|
|
|
|
DECLARE @EndDate DATETIME
SET @EndDate = '20091230' Something like this?
I are Troll
|
|
|
|
|
The default format of a date in sql = MM/dd/yyyy , so 30/12/2009 is indeed an invalid date.
So there are three ways to solve this:
- Use
set DateFormat dmy - use
set @EndDate = '12/30/2009' - use
set @EndDate = '20091230'
The first option will allow you to use your own way of using dates.
In the second option you use the current settings of the server. You cannot always be sure of this setting, so I wouldn't use this.
The third option is using the ISO format for dates. I prefer this method because it is language independent.
Wout Louwers
|
|
|
|
|
Thank you that did the trick! thx for all the help
|
|
|
|
|
I have a series of time series data. How do I construct a SQL statement to find whether the minimum (or trough) between 2 different dates is smaller than both the values on the starting date and the ending date? My table has StockName, Date, and Price column.
The purpose of this query is to find all the stocks when their price slopes changes from negative to positive. So if a minimum point does exists between the 2 dates but is smaller than either starting and ending values, it means there's a slope change like the following:
*................*..
..*............*....
....*........*......
.......*....*.......
.........*..........
Could you please provide a sample query statement?
Much thanks in advance!
|
|
|
|
|
Hi,
for begin point B and end point E, you could
- select all points X between B and E;
- order them by the distance between val(X) and the smallest of begin and end points = MIN(val(B),val(E));
If any record is selected, you have a V pattern, and specifying "TOP 1" would yield it.
|
|
|
|
|
Thank yuo Luc, that is pure elegancy, much better than my original idea which involves 2 separate comparisons.
Could you please let me know how to write that query statement? I currently have the following which doesn't work....
The time series data is stock price and I want to retrieve all the stocks with that V shape price pattern:
[Edit] Sorry for some reason when I tried to post my code, I got an error internet message and not able post the message. Could you please show me a sample of the query? I'd greatly appreciate it!
modified on Tuesday, December 29, 2009 4:04 AM
|
|
|
|
|