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
5
123 Views
Last Modified: 2016-12-01
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
5 Comments
 
LVL 11

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 11

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now