Hi i'm new to programming . I'm creating a project in C#.net using visual studio.
I'm facing problem. Creating a login button and a new login ID button. the new login ID should store the details in the database and when the same is entered in the login text box, it has to check the username and password from this database. If it is correct go the next page else error message.
I'm also facing problem in sql connection
the error shown is "can not connect in default setting"

Can any one pls help me. I'll be happy if i get the codings for it....pls do explain how to impliment the code...

Thanks in advance

set ur the data source ur going to use in "app.config"

<add name="Employee_Maintenance.Properties.Settings.ERPConnectionString"
            connectionString="Data Source=Kepler\SQLEXPRESS;Initial Catalog=ERP;Persist Security Info=True;User ID=antonette;Password=ilovemis"
            providerName="System.Data.SqlClient" />

or try to visit connectionstring.com!

Then try to use the line of code below.

private void btnLogin_Click(object sender, EventArgs e)
            SqlConnection Connect = new SqlConnection();
            Connect.ConnectionString = @"Data Source=Kepler\SQLEXPRESS;" + "Initial Catalog= ERP;" + "Persist Security Info=True;" + "User ID=antonette;" + "Password=ilovemis";
            SqlCommand cmd = new SqlCommand("SELECT ISNULL(username, '') AS username, ISNULL(password, '') AS password FROM employee WHERE username='" + txtUserName.Text + "' and password='" + txtPassword.Text + "'", Connect);

            SqlDataReader dr = cmd.ExecuteReader();

            string userText = txtUserName.Text;
            string passText = txtPassword.Text;

                    if (dr.Read()) 
                        frmMain main = new frmMain();
                        MessageBox.Show("Invalid UserName or Password.");                    

Hope it works for you! ;)

Thanks a lot Mr. Muzikhera it worked perfectly.......

I was worried about that ....now I'm releaved.

Thanks once again...

I have some more doubts hope u will answer that too.....

Hey I think you have problem in ur personal syntax I`m not a male/Mr. muzikhera just to be aware I`m a girl/female ok?

Good to hear that it works for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.