Tag: #sql winforms

如何在datagridview中将第二列的两列数据相乘

我想将两列的数据相乘并在第三列中显示它。 例如: 1st Column: Quantity 2nd Column: Rate 3rd Column: Price 我希望乘以用户输入数量和Quantity=2的数据,如Quantity=2 , rate=50自动在价格列我希望100出现。 同时我想分割为用户输入数量和Price=100的数据,如Price=100 , rate=50自动在Quantity栏中我要2出现。 当用户输入数量和Price=100的数据,如Price=100 , Quantity=2自动在费率列我想要50出现。 这三个将在同一个datagridview中发生。 用户只能输入这三个中的任意两个字段,第三个字段将自动进入。 使用C#,VS2008,SQL 2008 private void dataGridView2_CellEndEdit(object sender, DataGridViewCellEventArgs e) { int quantity,rate; for (int i = 0; i < dataGridView2.Rows.Count; i++) { if(int.TryParse(dataGridView2.Rows[i].Cells[1].Value.ToString(), out quantity) && int.TryParse(dataGridView2.Rows[i].Cells[2].Value.ToString(), out rate)) { int price = quantity […]

Windows表单应用程序exception

我得到应用程序exception at System.Windows.Forms.CurrencyManager.get_Item(Int32 index) at System.Windows.Forms.CurrencyManager.get_Current() at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs e) at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred) at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick) at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown) at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e) at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at […]

DataGridView – 如何仅为单个列设置货币格式

我正在尝试将datagridview用于购物篮。 我有它显示客户的篮子,但我希望它显示价格列的货币,但我也有一个数量列,所以如果我把默认样式作为货币,那么它将更改两列货币格式。 我想要做的是将货币格式添加到价格列,但不添加到数量列。 这是显示购物篮的代码(Form_load) using (var con = new SqlConnection(connectionString)) { SqlDataAdapter dataadapter = new SqlDataAdapter( “select p.productname ‘Product Name’, b.productquantity ‘Quantity’, c.categoryname ‘Category’, p.price ‘Current Price’ ” + “from basket b join products p on b.productid = p.productid ” + “join Categories c on c.categoryid = p.categoryid ” + $”where b.customerid = {CustomerId}”, con); […]

使用C#winform中的app.config访问数据库连接字符串

我似乎无法在我的c#winforms应用程序中访问app.config数据库连接字符串。 app.config代码 C#代码: SqlConnection conn = new SqlConnection(); conn.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings[“MyDBConnectionString”]; 当我尝试C#代码时,我收到一条消息: 警告1’System.Configuration.ConfigurationSettings.AppSettings’已过时:’此方法已过时,已被System.Configuration取代!System.Configuration.ConfigurationManager.AppSettings’ 但是,当我尝试使用时: conn.ConnectionString = System.Configuration!System.Configuration.ConfigurationManager.AppSettings[“MyDBConnectionString”]; 我收到一个错误: 只能将赋值,调用,递增,递减和新对象表达式用作语句