Solved

Problem with SqlConnection

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

635 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