Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem with SqlConnection

Posted on 2016-10-23
4
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
Nakul Vachhrajani earned 2000 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 14

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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

721 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