Solved

Problem with SqlConnection

Posted on 2016-10-23
4
199 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 13

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 13

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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
I have a large data set and a SSIS package. How can I load this file in multi threading?
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

729 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