主题:[讨论]高手帮我看看这段代码
已经编好下面的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=addr.mdb");
OleDbCommand cmd = new OleDbCommand();
OleDbDataReader reader;
cmd.CommandText = " SELECT * FROM addr WHERE Code ='110000'";
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
conn.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
MessageBox.Show("find record");
}
else
{
MessageBox.Show("no record");
}
conn.Close();
}
}
}
我想把查询得到的结果保存到一个字符串变量中,因为后面要使用查询得到的结果,该如何添加代码?谢谢!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=addr.mdb");
OleDbCommand cmd = new OleDbCommand();
OleDbDataReader reader;
cmd.CommandText = " SELECT * FROM addr WHERE Code ='110000'";
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
conn.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
MessageBox.Show("find record");
}
else
{
MessageBox.Show("no record");
}
conn.Close();
}
}
}
我想把查询得到的结果保存到一个字符串变量中,因为后面要使用查询得到的结果,该如何添加代码?谢谢!