Click here to Skip to main content
15,888,273 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;
namespace khtwa
{
    public partial class Form1 : Form
    {
        
        
        public Form1()
        {
            InitializeComponent();
        }
        string msg;

        
       
        SqlCeCommand cmd;
        DataSet ds = new DataSet();
        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
                textBox2.Text="";

                this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string y = (Application.StartupPath + "\\font.sdf");
             SqlCeConnection con = new SqlCeConnection(@"Data Source=" + y);
             con.Open();
                if (textBox1.Text == "" || textBox2.Text == "")
                {
                    MessageBox.Show(" Enter UserName and Password .");
                    return;
                }

                cmd = new SqlCeCommand("SELECT * FROM login where user='" + textBox1.Text + "' and password='" + textBox2.Text + "'", con);
                SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
               
                da.Fill(ds);
                int i = ds.Tables[0].Rows.Count;
                if (i == 1)
                {
                    msg = "Welcome " + textBox1.Text;
                    this.Hide();
                    Form2 f2 = new Form2();
                    f2.Show();
                    ds.Clear();

                }
                else
                {
                    MessageBox.Show("Not Registered User or Invalid Name/Password");
                    textBox2.Text = "";
                }
            }
           


        }
    }
Posted
Updated 9-Apr-14 13:54pm
v2
Comments
CHill60 9-Apr-14 19:56pm    
Try to not type your question into the title of your post ... use the Improve Question link to add the full error message that you received and put a more meaningful title in. Also indicate which line gives you the error
[no name] 9-Apr-14 20:10pm    
Try [user]. Don't use string concatenation to construct queries. Don't store passwords in plain text.

1 solution

1.Test your SQL into the SQL server first and maybe you put a wrong name for a field, or for table name (could be logins and not login !?), by using the same test data as in your application. So you should test the next SQL:
SELECT * FROM login where user= 'xxx' and password = 'yyyy'

2.After you will identify and correct the errors in your test above, you will can make corrections in your C# code;

3.You should not sent concatenate the user inputs directly into your SQL command text, because this could lead to SQL injection attacks; you should use SQL parameters (@user and @password).
 
Share this answer
 
v2
Comments
Mohamed Ragheb 10-Apr-14 11:33am    
thanks , i change name of colnm and work
Raul Iloc 10-Apr-14 23:55pm    
Welcome, so you should accept my solution!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900