ผมเขียนติด Error ตรงนี้มาเป็นชั่วโมงแล้วคับ visual studio ภาษา C# นี่คือตัวโค้ด
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 Order
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DataSet _dataset;
private OleDbConnection _conn;
private OleDbCommand _command;
private OleDbDataAdapter _adapter;
private void Form1_Load(object sender, EventArgs e)
{
string conStr = "Provider = Microsoft.Jet.OleDb.4.0;" + "Data Source =" + Application.StartupPath + @"\AppSharp.mdb";
_conn = new OleDbConnection(conStr);
_conn.Open(); // ส่วนที่เกิด Error ขึ้น
string sql = "SELECT * FROM Customers";
_command = new OleDbCommand (sql, _conn);
OleDbDataReader reader = _command.ExecuteReader();
while (reader.Read())
{
cmbCustomer.Items.Add(reader["CustomerName"]);
}
sql = "SELECT * FROM Products";
_command = new OleDbCommand(sql, _conn);
reader = _command.ExecuteReader();
while (reader.Read())
{
cmbProduct.Items.Add(reader["ProductName"]);
}
dateTimePicker1.Value = DateTime.Today;
cmbCustomer.SelectedIndex = 0;
cmbProduct.SelectedIndex = 0;
btnDelate.Enabled = false;
}
private void formOrder_FormClosing(object sender, FormClosingEventArgs e)
{
_conn.Close();
}
private void showOrders()
{
string sql = "SELECT * FROM Orders ";
sql = "WHERE CustomerName = @cust";
_command = new OleDbCommand (sql, _conn);
_command.Parameters.AddWithValue("cust", cmbCustomer.SelectedItem);
_adapter = new OleDbDataAdapter(_command);
_dataset = new DataSet();
_adapter.Fill(_dataset, "ord");
dataGridView1.DataSource = _dataset.Tables["ord"];
}
private void cmbCustomer_SelectedIndexChanged(object sender, EventArgs e)
{
showOrders();
}
--------------------------------------------------------------------------------------------------------------------------------------------------
ตรงนี้คือส่วนที่เกิด Error
พอจะช่วยแก้ไข Error ตรงนี้ได้ไหมคับ
เขียนโปรแกรมข้อมูลการสั่งซื้อ visual studio
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 Order
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DataSet _dataset;
private OleDbConnection _conn;
private OleDbCommand _command;
private OleDbDataAdapter _adapter;
private void Form1_Load(object sender, EventArgs e)
{
string conStr = "Provider = Microsoft.Jet.OleDb.4.0;" + "Data Source =" + Application.StartupPath + @"\AppSharp.mdb";
_conn = new OleDbConnection(conStr);
_conn.Open(); // ส่วนที่เกิด Error ขึ้น
string sql = "SELECT * FROM Customers";
_command = new OleDbCommand (sql, _conn);
OleDbDataReader reader = _command.ExecuteReader();
while (reader.Read())
{
cmbCustomer.Items.Add(reader["CustomerName"]);
}
sql = "SELECT * FROM Products";
_command = new OleDbCommand(sql, _conn);
reader = _command.ExecuteReader();
while (reader.Read())
{
cmbProduct.Items.Add(reader["ProductName"]);
}
dateTimePicker1.Value = DateTime.Today;
cmbCustomer.SelectedIndex = 0;
cmbProduct.SelectedIndex = 0;
btnDelate.Enabled = false;
}
private void formOrder_FormClosing(object sender, FormClosingEventArgs e)
{
_conn.Close();
}
private void showOrders()
{
string sql = "SELECT * FROM Orders ";
sql = "WHERE CustomerName = @cust";
_command = new OleDbCommand (sql, _conn);
_command.Parameters.AddWithValue("cust", cmbCustomer.SelectedItem);
_adapter = new OleDbDataAdapter(_command);
_dataset = new DataSet();
_adapter.Fill(_dataset, "ord");
dataGridView1.DataSource = _dataset.Tables["ord"];
}
private void cmbCustomer_SelectedIndexChanged(object sender, EventArgs e)
{
showOrders();
}
--------------------------------------------------------------------------------------------------------------------------------------------------
ตรงนี้คือส่วนที่เกิด Error
พอจะช่วยแก้ไข Error ตรงนี้ได้ไหมคับ