C#获取数据库字段的值看是否具有“管理员”权限
第1个回答 2015-06-12
SqlConnection conn = new SqlConnection("连接字符串");
try
{
conn.Open();
DataTable dtCustom = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter("select * from users",conn);
sda.Fill(dtCustom);
for (int i = 0; i < dtCustom.Rows.Count; i++)
{
//i=0为你取第一行的时候
int status = Convert.ToInt32(dtCustom.Rows[i]["字段名称"]);
if (status == 0)
{
//等于0的时候你的操作
}
else if (status == 1)
{
//等于1的时候你的操作
}
else {
//其它时候的操作
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
try
{
conn.Open();
DataTable dtCustom = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter("select * from users",conn);
sda.Fill(dtCustom);
for (int i = 0; i < dtCustom.Rows.Count; i++)
{
//i=0为你取第一行的时候
int status = Convert.ToInt32(dtCustom.Rows[i]["字段名称"]);
if (status == 0)
{
//等于0的时候你的操作
}
else if (status == 1)
{
//等于1的时候你的操作
}
else {
//其它时候的操作
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
第2个回答 2015-06-12
SqlConnection conn = new SqlConnection(@"server=.;database=mysql;integrated security=true");//创建数据库连接
conn.Open();、、打开数据库
SqlCommand cmd = new SqlCommand("select * from tb_name where number='" +number+ "'", conn);//可以把number替换成1/0.
int returnvalue = cmd.ExecuteNonQuery();
if (returnvalue != -1)
MessageBox.Show("存在", "提示");
conn.close();
或者定义一个全局变量power
private void frmMain_Load(object sender, EventArgs e)
{
switch (Power)
{
case "2": toolStripStatusLabel4.Text = "超级管理员"; break;
case "1": toolStripStatusLabel4.Text = "经理"; break;
case "0": toolStripStatusLabel4.Text = "客户"; break;
}
}
你试试,不懂在问 qq:1471857471本回答被网友采纳
conn.Open();、、打开数据库
SqlCommand cmd = new SqlCommand("select * from tb_name where number='" +number+ "'", conn);//可以把number替换成1/0.
int returnvalue = cmd.ExecuteNonQuery();
if (returnvalue != -1)
MessageBox.Show("存在", "提示");
conn.close();
或者定义一个全局变量power
private void frmMain_Load(object sender, EventArgs e)
{
switch (Power)
{
case "2": toolStripStatusLabel4.Text = "超级管理员"; break;
case "1": toolStripStatusLabel4.Text = "经理"; break;
case "0": toolStripStatusLabel4.Text = "客户"; break;
}
}
你试试,不懂在问 qq:1471857471本回答被网友采纳