求助高手,一個C#與SQL的問題,在線等.......
我想在C#里面,從兩個textbox里得到數據,然後去數據庫查詢,得到一個字段的數據,得到這些數據值後,把值賦給一個listbox,請高手指教怎麼樣做。我寫的代碼如下,不過很多地方不對。
string strbox2 = txtbox2.Text;
string strbox3 = txtbox3.Text;
string Querystr = "select 品名,類別 from ModProcure.dbo.BF where 品名 like ' " + strbox2 + "% ' AND 類別 like ' " + strbox3 + "% ' ";
conn.Open();
SqlCommand cmd = new SqlCommand(Querystr, conn);
SqlDataReader Query_value = cmd.ExecuteReader();
if (Query_value.VisibleFieldCount < 1)
{
MessageBox.Show( "您輸入的報廢模具名稱有誤,請重新輸入 ");
}
else
{
Query_value.Close();
string Querystr1 = "SELECT PicPath FROM ModProcure.dbo.M_Mod_Data2 WHERE Pno= ' " + strbox2 + " ' AND Kind= ' " + strbox3 + " ' ";
//Console.Write(Querystr1);
SqlCommand cmd1 = new SqlCommand(Querystr1, conn);
SqlDataReader Query_value1 = cmd1.ExecuteReader();
//getpath = Query_value1.GetValue(0);
//Console.Write(Query_value1.GetString(0));
//if (Query_value1.VisibleFieldCount < 1)
&n