如何将存储过程满足条件的查询结果放在dataGridView中显示出来
try
{
string directory = Directory.GetCurrentDirectory() + "\\aa.ini";
IniFile db = new IniFile(directory);
SqlConnection conn = db.GetDBConn();
conn.Open();
SqlCommand cm = new SqlCommand("kefang_fanghaocha2", conn);
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.Add("@fang",SqlDbType.VarChar);
cm.Parameters["@fang"].Value = textBox5.Text;
SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
DataSet ds = new DataSet();
dr.Fill(ds, "fanghao");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "fanghao";
}
else
{
MessageBox.Show("找不到该记录!!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
[此贴子已经被作者于2007-8-13 2:51:17编辑过]