String strconn, strsql;
OleDbConnection myconn;
OleDbCommand mycomm;
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb";
myconn = new OleDbConnection(strconn);
myconn.Open();
comboBox1.Text.Replace('\'', '“');
strsql = "select * from h_admin where h_username='" + comboBox1.Text + "' and " + "h_password='" + textBox1.Text+"'";
mycomm = new OleDbCommand(strsql, myconn);
上面的结果查询后,我要怎么把第1条记录的2个字段分别保存在2个变量上面
OleDbConnection myconn;
OleDbCommand mycomm;
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data.mdb";
myconn = new OleDbConnection(strconn);
myconn.Open();
comboBox1.Text.Replace('\'', '“');
strsql = "select * from h_admin where h_username='" + comboBox1.Text + "' and " + "h_password='" + textBox1.Text+"'";
mycomm = new OleDbCommand(strsql, myconn);
上面的结果查询后,我要怎么把第1条记录的2个字段分别保存在2个变量上面
if (reader.Read())
{
string s1 = reader[0].ToString();
string s2 = reader[1].ToString();
}
if (reader.Read())
{
string s1 = reader[0].ToString();
string s2 = reader[1].ToString();
}
这只是把值直接取出来。不是很理解你的意思。
dataset ds=new dataset();
oleadp.fill(ds);
if(ds.rows.count>0)
{
string s1=ds.table[0].rows[0]["字段名称1"].tostring();
string s2=ds.table[0].rows[0]["字段名称2"].tostring();
}