【发布时间】:2015-05-07 17:45:20
【问题描述】:
我正在尝试从组合框中的项目中获取价格。有什么想法吗?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Aplicatie_proiect
{
public partial class Form2 : Form
{
private OleDbConnection connection = new OleDbConnection();
public Form2()
{
InitializeComponent();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\SleepyHitman- V2\Documents\Inventory1.accdb;
Persist Security Info=False;";
}
private void txt_order_Click(object sender, EventArgs e)
{
Double PT = new Double();
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "insert into Comenzi (Produs,Cantitate) values('"+txt_Produs.Text+"','"+txt_Cantitate.Text+"',)" ; //+ sa adaug useru care e logat din form 1
command.ExecuteNonQuery();
connection.Close();
}
private void Form2_Load(object sender, EventArgs e)
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "select * from Inventory";
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
txt_Produs.Items.Add(reader["Produs"].ToString());
}
connection.Close();
}
private void txt_Produs_SelectedIndexChanged(object sender, EventArgs e)
{
**connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "select * from Inventory where Pret ='" + txt_Produs.Text + "'";
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
txt_Pret.Text = reader["Pret"].ToString();
}
connection.Close();**
}
}
}
【问题讨论】:
-
您应该更清楚地说明问题出在哪里,在哪里,以及您的预期。
-
当我从组合框中选择一个项目时,我想获得价格(Pret),这样用户就可以看到该项目的价格是多少,然后选择数量。
-
请编辑您的问题,不要在 cmets 中发布代码。那里看不懂。
-
来自 txt_Produs_selectedIndexChanged 有我的问题也很抱歉我昨晚没睡,现在很难集中注意力 + 我在 20 分钟后要考试,我也试着重复一遍跨度>