if (textBox1.Text.Trim().Length != 4)
{
MessageBox.Show("請輸入完整的搜索條件", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
SqlConnection conn=new SqlConnection ("server=xxxx;UID=xx;PASSWORD=xxx;DATABASE=xxx");
SqlCommand cmd = new SqlCommand();
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("sp_QueryM", conn);
// cmd.CommandText = "sp_QueryM";
cmd.CommandType = CommandType.StoredProcedure;
sda.SelectCommand.Parameters.Add("@cpm",textbox1.text.trim() );
// sda.SelectCommand.Parameters.Add(textBox1.Text.Trim(), "@cpm");
// string sql = " execute sp_QueryM, '" + textBox1.Text.Trim() + "'";
// cmd.Parameters[0].Value = "ABC"; // 暫且不用存儲過程來實現數據 的查詢
cmd.Connection = conn;
DataSet ds = new DataSet();
sda.Fill(ds,"ThisYueJie");
int i = ds.Tables[0].Rows.Count;
if (i == 0)
{
MessageBox.Show("未查詢到數據!");
return;
}
dgv1.DataSource = ds.Tables[0];
conn.Close();
这用写会提示程序或函数没有值