資料庫combobox
A. 在DELPHI中COMBOBOX如何連接資料庫的內容
combobox需要通過代察慶碼將塵辯資料庫中的記錄一條條加入
query1.open;
combobox1.items.clear;
while
not
query1.eof
do
begin
combobox1.items.add(query1.fieldbyname('派沒缺欄位1').asstring);
query1.next;
end;
B. C#中comboBox如何綁定資料庫
你把你的數據代碼放在 comboBox1_SelectedIndexChanged裡面是干什麼啊,你這個永遠都不會執行的!!
把你的
connection = new sqlConnection(connString);
string cid = comboBox1.SelectedValue.ToString();
string sql = string.Format("Select item from article where article_ID=[0]", cid);
try
{
dataAdapter = new SqlDataAdapter(sql,connection);
DataSet da = new DataSet();
dataAdapter.Fill(da);
comboBox1.DataSource = da.Tables[0];
comboBox1.ValueMember = "article_ID";
comboBox1.DisplayMember = "item";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "操作資料庫出錯!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
connection.Close(); // 關閉資料庫連接
}
這段代碼放在窗體的load事件裡面去
C. ComboBox如何實現對資料庫模糊查詢!!!
方案1:建議你將模糊搜索的事件放到一個按鈕中執行,胡陪比如查詢,點擊後再通過SQL的like語句將結果放入combobox控制項中,這樣就行了。
方案2:你在textbox的change事件里寫模糊查詢語句,將查詢的內容實時的放入combobox控制項中中兆即可,但是這個要根據你資料庫的具體容量來褲培蠢定,如果資料庫信息過於龐大,不建議這樣。
D. c#中如何將combobox中的值存入資料庫
可以用笑猜一個SqlDataReader 將檔升灶資料庫的信行扮息加入到ComboBox控制項中:
SqlDataReader read=new SqlDataReader("select id from user");
if(read.hasrows)
{
while(read.Read())
commobox.items.add(read["id"].tostring());
}
E. 如何將combobox的值寫進資料庫中
首先你如蘆要新建一個數據肆派庫,然後有操作資料庫的類庫,然後再後台獲取combobox的值,然後再用操作資料庫的類庫操作這個值,把它保存裂橡賀在你的資料庫的某張表裡的某個欄位