"Data type mismatch in criteria expression." Fehler

Bekomme ich eine "Data type mismatch in criteria expression." Fehler beim ausführen dieses Codes auf einer Datenbank, aber es funktioniert einwandfrei auf einer anderen Datenbank.
Wenn Sie versuchen, kopieren Sie die entsprechende Tabelle in andere Datenbank, und führen Sie es von ihm das Programm nicht wieder!

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;

namespace Project
{
public partial class Login : Form
{
    public Login()
    {
        InitializeComponent();
    }

    private void Login_Load(object sender, EventArgs e)
    {

    }

    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void LoginButton_Click(object sender, EventArgs e)
    {
        DAL conn = new DAL(@"|DataDirectory|\ProjectDB.accdb");
        DataSet ds = conn.GetDataSet("Select * from Secretarys where SecretaryUsername = "+UserNameBox.Text.ToString());
        if (ds.Tables[0].Rows[0][0].ToString().Equals(PassowrdBox.Text))
            MessageBox.Show("asd","sdfa");
    }
}
}

Klasse "DAL", das ich verwende.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.OleDb;

///<summary>
///Summary description for DAL
///</summary>
public class DAL
{
private string dbPath;
private OleDbConnection conn;
private OleDbCommand command;
private OleDbDataAdapter adapter;
private string stQuery;

public DAL(string dbPath)
{
    this.dbPath = dbPath;
    string ConnectionString = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}", this.dbPath);
    conn = new OleDbConnection(ConnectionString);
    command = new OleDbCommand(stQuery, conn);
    adapter = new OleDbDataAdapter(command);
}

public DataSet GetDataSet(string strSql)
{
    DataSet ds = new DataSet();
    command.CommandText = strSql;
    adapter.SelectCommand = command;
    adapter.Fill(ds);
    return ds;
}
public bool InsertRow(string sqlInsert)
{
    int rowsEffected;
    command.CommandText = sqlInsert;
    conn.Open();
    rowsEffected = command.ExecuteNonQuery();
    conn.Close();
    return (rowsEffected > 0);

}

public string GetData(string strSql)//שולפת נתונים מהטבלת המשתמשים שנמצאת באקסס
{
    string st = "";
    DataSet ds = new DataSet();
    command.CommandText = strSql;
    conn.Open();
    st = command.ExecuteScalar().ToString();
    conn.Close();
    return (st);
}

public void UpdateRow(string sqlInsert)//הוספת נתונים לטבלת החברים באקסס
{

    command.CommandText = sqlInsert;
    conn.Open();
    command.ExecuteNonQuery();
    conn.Close();

}
public void DeleteDataSet(DataSet ds)
{

    OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
    adapter.DeleteCommand = builder.GetDeleteCommand();
    conn.Open();
    adapter.Update(ds);
    conn.Close();
}
}
InformationsquelleAutor user2044047 | 2013-02-05
Schreibe einen Kommentar