我真累了,请有人帮我这里:( [英] i really got tired , please someone help me here :(

查看:70
本文介绍了我真累了,请有人帮我这里:(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要非常帮助....从早上到现在(晚上)我正在通过访问2007进行c#登录...我探索了很多谷歌你知道的任何网站,但没有一个没有回复...请帮助meeee .....我真累了!

hi , i am in needed in Helping very much .... from morning till now(night) i 'm working on c# login through access 2007 ... i explore alot google any websites u know but none of them doesnt reply ... please help meeee ..... i really got tired!

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.OleDb;

namespace WindowsFormsApplication34
{
    public partial class Form1 : Form
    {
        public OleDbConnection con = new OleDbConnection();
        public Form1()
        {
            InitializeComponent();
            string strcon = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\\Users\\Persian\\Desktop\\a.accdb ";
            con = new OleDbConnection(strcon);
            try
            {
                con.Open();
            }
            catch (OleDbException e)
            {
                MessageBox.Show("Access Error");
                MessageBox.Show("Error code= " + e.ErrorCode);
                MessageBox.Show("Error Message=" + e.Message);

            }
            catch (InvalidOperationException e)
            {
                MessageBox.Show("Invalid message"+ e.Message);
            }
            if (con.State != ConnectionState.Open)
            {
                MessageBox.Show("Database connection is failed");
                Application.Exit();
            
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string cmdstring = "SELECT * FROM log";
            cmdstring += "WHERE (user=@p) AND (pass=@q)";
            OleDbDataAdapter logindataadapter = new OleDbDataAdapter();
            DataTable accdatatable = new DataTable();
            OleDbCommand acccommand = new OleDbCommand();
            Form1 a = new Form1();
            acccommand.Connection = con;
            acccommand.CommandType = CommandType.Text;
            acccommand.CommandText = cmdstring;
            acccommand.Parameters.Add("@p",OleDbType.Char).Value = textBox1.Text;
            acccommand.Parameters.Add("@q", OleDbType.Char).Value = textBox2.Text;
            logindataadapter.SelectCommand = acccommand;
            logindataadapter.Fill(accdatatable);
            if (accdatatable.Rows.Count > 0)
            {
                MessageBox.Show("Login susseful");
                a.Show();
                this.Hide();

            }
            else
                MessageBox.Show("No Matched username/password found");
            accdatatable.Dispose();
            acccommand.Dispose();
            logindataadapter.Dispose();
        }
    }
}





实际上它会运行但当我输入正确的用户并传递时这一行



acctually it runs but when i enter right user and pass on this line

logindataadapter.Fill(accdatatable);

说这个错误FROM子句中的语法错误...它的问题是什么朋友



非常感谢

is saying this error "syntax error in FROM clause" ... what is its problem friends

many thanks

推荐答案

你需要在log之后或WHERE之前添加一个空格。



当你是得到SQL语法错误,明智的做法是将它带入SQL Server MS并运行查询直到它工作。将其移回C#时,请确保所有空格和标点符号仍然存在。



此外,在调试时,如果查看查询的连接字符串,则会有注意到空间不足。
You need to add a space after "log" or before "WHERE".

When you are getting SQL syntax errors, it is wise to take that into SQL Server MS and run the query until it works. When moving it back to C#, make sure all spaces and punctuation persist.

Also, while debugging, if you looked at the concatenated string of your query, you would have noticed the lack of the space.


这篇关于我真累了,请有人帮我这里:(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆