namespace primarykeycheck
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection myConn;
OleDbCommand myComm;
string queryString;
public void connectDB()
{
myConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\rummykhan\MCS\Spring 2013\Object Oriented Programming\My Apps\Testing\Database Apps\string as Primary key\primarykeycheck\db.accdb");
}
public string fetchName(string ID)
{
string Name;
queryString = "select dbName from mydb where dbID =" + ID;
myComm = new OleDbCommand(queryString, myConn);
myConn.Open();
Name = (string)(myComm.ExecuteScalar()).ToString();
myConn.Close();
return Name;
}
private void btn_fetch_Click(object sender, EventArgs e)
{
connectDB();
txtName.Text = fetchName(txtID.Text);
}
当 id 数据类型为字符串时,我正在努力获取名称,bt 我面临这个问题“标准表达式中的数据类型不匹配”我也尝试过 Name = (string)myComm.ExecuteScalar();