Solved

Problem with SqlConnection

Posted on 2016-10-23
  • MS SQL Server
  • MS SQL Server 2005
  • MS SQL Server 2008
  • MySQL Server
  • .NET Programming
  • +2
4
168 Views
Last Modified: 2016-12-14
Guys I have a problem with SqlConnection at this code and I cant find whats missing


using System.Data.SqlClient
   
SqlConnection sc = new SqlConnection("DataSource=(local)Initial Catalog=SignUp4free;Intergrated Security=true;");
            sc.Open();
            SqlCommand sco = new SqlCommand("Select from TextBox1 where username=" + textBox1.Text + " and from TextBox2 where password=" + textBox2.Text + "");
            SqlDataReader sdr;
            sdr = sco.ExecuteReader();
            int count = 0;
            
            while (sdr.Read());
            {
                count += 1;
                count.Equals(count + 1);

            }
            if (count == 1);
            {
                MessageBox.Show("Ok");
                
                


            }

Open in new window

so anyone help;
0
Comment
Question by:Brian Smith
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Nakul Vachhrajani earned 500 total points
ID: 41857361
What is the error that you are facing? By the way, I think you are missing a semi-colon in the connection string:

SqlConnection sc = new SqlConnection("DataSource=(local)Initial Catalog=SignUp4free;Intergrated Security=true;")

Open in new window


should be:

SqlConnection sc = new SqlConnection("DataSource=(local);Initial Catalog=SignUp4free;Intergrated Security=true;")

Open in new window

1
 
LVL 12

Expert Comment

by:Nakul Vachhrajani
ID: 41857364
Also, your SQLCommand is incorrect. I assume TextBox1 and TextBox2 are UI controls, not tables. Assuming that your table where you store user names and passwords is "dbo.MyUser", your command should be:

SqlCommand sco = new SqlCommand("Select from dbo.MyUser where username=" + textBox1.Text + " and password=" + textBox2.Text + "");

Open in new window


The following is incorrect:
SqlCommand sco = new SqlCommand("Select from TextBox1 where username=" + textBox1.Text + " and from TextBox2 where password=" + textBox2.Text + "");

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question