[英]get boolean value from access database in c#
我在 C# .Net 框架中编写了一个程序,该程序使用 Access 数据库,每个用户对不同部分的访问以布尔格式存储在其中。
我在检查数据库中它们是 True 还是 False 时遇到了问题。
我只需要知道如何从 Access 中导入这些值并将它们存储在其他变量中以访问它们。
登录表单源代码👇👇👇
public partial class FormLogin : Form
{
static OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=kft21_gym.accdb");
OleDbDataAdapter da = new OleDbDataAdapter("", con);
DataSet ds = new DataSet();
Boolean BlResult = false;
public Boolean Bsabtnam = false;
public Boolean Bmodiriathamrahan = false;
public Boolean Bbaresisavabegh = false;
public Boolean Bmodiriatkomod = false;
public Boolean Bmodiriatkarbaran = false;
public Boolean Bgetbackup = false;
public Boolean Bgetrestore = false;
public FormLogin()
{
InitializeComponent();
}
private void Checking()
{
string check = "SELECT ID FROM Login WHERE UserName='" + txtUserName.Text + "' AND UserPassword='" + txtPassword.Text + "' ";
OleDbDataAdapter da = new OleDbDataAdapter(check, con);
da.Fill(ds, "t1");
if (ds.Tables["t1"].Rows.Count != 0)
{
BlResult = true;
this.BackgroundImage = imgTrue.Image;
lblEnter.Visible = true;
//need to change them if the value is TRUE
/*
Bsabtnam = ???????
Bmodiriathamrahan = ???????
Bbaresisavabegh = ???????
Bmodiriatkomod = ???????
Bmodiriatkarbaran = ???????
Bgetbackup = ???????
Bgetrestore = ???????
*/
}
else
{
BlResult = false;
this.BackgroundImage = imgFalse.Image;
lblEnter.Visible = false;
}
}
private void txtUserName_TextChanged(object sender, EventArgs e)
{
Checking();
}
private void txtPassword_TextChanged(object sender, EventArgs e)
{
Checking();
}
private void txtUserName_KeyPress(object sender, KeyPressEventArgs e)
{
if (Convert.ToInt32(e.KeyChar) == 13 && BlResult == true)
{
this.Close();
}
else if(Convert.ToInt32(e.KeyChar) == 27)
{
Application.Exit();
}
}
private void txtPassword_KeyPress(object sender, KeyPressEventArgs e)
{
if (Convert.ToInt32(e.KeyChar) == 13 && BlResult == true)
{
this.Close();
}
else if (Convert.ToInt32(e.KeyChar) == 27)
{
Application.Exit();
}
}
private void FormLogin_FormClosing(object sender, FormClosingEventArgs e)
{
if (BlResult == false)
{
Application.Exit();
}
}
}
好吧,如果您的问题是如何从加载的表中取出数据(消除一些非常古老的记忆),我相信答案是在表中使用双索引:
dim value as Variant
dim table as …
table = ds.Tables[“t1”]
value = table[i][j]
另一方面,如果您的问题是如何访问布尔值而不是双精度或字符串……我记得布尔值在 Access 中存储为整数。 所以检查变体,看看它是否是一个int。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.