PDA

View Full Version : خطایی در حین لاگین شدن



omidrayaneh.68
شنبه 28 اردیبهشت 1392, 14:18 عصر
سلام من سه تا فیلد دارم id,username,password که همه از نوع nvarchar هست اما هنگام reader کرن پیغام خطا میده
متن خطا
Incorrect syntax near the keyword 'user'.
کد ها

public partial class Login : Form
{
static SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\system_abzar.mdf;integrated security=true;User Instance=True");
//SqlDataAdapter da = new SqlDataAdapter("", con);
DataSet ds = new DataSet();
SqlCommand command = new SqlCommand();

public Login()
{
InitializeComponent();
}

private void enter_Click(object sender, EventArgs e)
{

con.Open();
command.Connection = con;
command.CommandText = "SELECT username,password from user WHERE username=@user AND password=@pass";
command.Parameters.AddWithValue("@user", textBox1.Text);
command.Parameters.AddWithValue("@pass", textBox2.Text);
SqlDataReader Reader;
Reader = command.ExecuteReader();


if (Reader.HasRows == true)
{

MessageBox.Show("ok");con.Close();
}


else
{

MessageBox.Show("no");
con.Close();
}


}

omidrayaneh.68
شنبه 28 اردیبهشت 1392, 14:21 عصر
لعنتی تا حالا این جوری نشده بود هر جور دیگه ای هم مینویسم ارور میده
کسی نیست یه راهنمایی کوچیک بکنه فک نکنم کد هام ایرادی داشته باشه قبلا هم این کارو انجام دادم این بار اصلا نمیشه

esafb52
شنبه 28 اردیبهشت 1392, 14:37 عصر
ظاهرا خط کامنتکسن خطا داره
اینو ببین
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.SqlClient;

namespace CheckUserNameAndPassword
{
public partial class Form1 : Form
{
private SqlConnection objconnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector y|\Dbase_UP.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
private SqlCommand objcommand;

public Form1()
{
InitializeComponent();
}

private void btnLogin_Click(object sender, EventArgs e)
{
int i = 0;
try
{

if ((txtUserName.Text == string.Empty) || (txtPassword.Text == string.Empty))
{
MessageBox.Show("Enter Data !");
return;
}

objcommand = new SqlCommand("SELECT COUNT(*) FROM Tbl_Users " +
"WHERE UserName=@UserName AND Password=@Password", objconnection);

objcommand.Parameters.AddWithValue("@UserName", txtUserName.Text.ToString());
objcommand.Parameters.AddWithValue("@Password", txtPassword.Text.ToString());

if (objconnection.State == ConnectionState.Closed)
{
objconnection.Open();
i =(int) objcommand.ExecuteScalar();
}//end if

objconnection.Close();

if (i > 0)
{
Form2 frm2 = new Form2();
frm2.Show();
}
else
MessageBox.Show("No Authentication !");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
i = 0;
objconnection.Close();
}
}
}
}

omidrayaneh.68
شنبه 28 اردیبهشت 1392, 15:06 عصر
آقا من اینا درست کردم بازم پیغام
Incorrect syntax near the keyword 'user'. رو میده
اسم تیبل من user هست
امکان داره که ایراد از table باشه؟؟؟؟؟؟؟؟؟؟؟؟؟
ممنون

omidrayaneh.68
شنبه 28 اردیبهشت 1392, 15:41 عصر
مشکل حل شد باید اسم جدول رو داخل براکت میذاشتم

sajadzare
شنبه 29 تیر 1392, 09:21 صبح
دوست عزیز تابع hasrows رو میذاری ؟ منم لازم دارم