我正在使用Windows窗體,我想創建一個方法,它將根據datagridview中ComboBox中的項目簡單查看所有數據。如何將我的gridview連接到數據庫?
private void InsertReceipt()
{
decimal Stub;
Stub = decimal.Parse(txtAmount.Text)/2000;
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO Ticket(CustomerID, Date, Store, Amount, NoStub)" +
"VALUES (@CustomerID, @Date, @Store, @Amount, @NoStub) ";
cmd.Parameters.AddWithValue("@CustomerID", cboName.SelectedValue);
cmd.Parameters.AddWithValue("@Date", dtpDate.Value.Date.ToString());
cmd.Parameters.AddWithValue("@Store", txtStore.Text);
decimal amount = decimal.Parse(txtAmount.Text);
cmd.Parameters.AddWithValue("@Amount", amount);
cmd.Parameters.Add("@NoStub", SqlDbType.Decimal).Value = Stub;
cmd.ExecuteNonQuery();
}
這是字段,我需要查看所有的數據,這取決於組合框內的項目。
你有什麼錯誤或什麼? –
綁定Gridview,像''select * from tb where cols = combox.value'這樣的查詢引用:http://satindersinght.blogspot.in/2012/08/how-to-addupdate-record-using-gridview.html –
想象一下你是另一個正在閱讀這個問題的人。你能理解這個問題嗎? – rajeemcariazo