|
 |
|
ต้องการนำค่า string จาก database ใส่ array แล้วนำมาตรวจสอบกับค่าที่รับจาก textbox ว่าซ้ำหรือไม่ก่อน add ลง datagrid |
|
 |
|
|
 |
 |
|
มันยัง add ค่าที่ซ้ำลง datagrid อยู่ครับ ช่วยผมดูหน่อยครับว่าพลาดตรงไหน
Code (C#)
private void addButton_Click(object sender, EventArgs e)
{
OleDbConnection objConn;
OleDbDataAdapter dtAdapter;
DataTable dt = new DataTable();
String strConnString;
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=SparesStore.mdb;";
objConn = new OleDbConnection(strConnString);
objConn.Open();
String strOleDb;
strOleDb = "SELECT [เลขที่] FROM SalesOrder";
dtAdapter = new OleDbDataAdapter(strOleDb, objConn);
dtAdapter.Fill(dt);
dtAdapter = null;
objConn.Close();
objConn = null;
for (int i = 0; i <= dt.Rows.Count - 1; ++i)
{
if (invId.Text == dt.Rows[i].ToString())
{
MessageBox.Show("เลขที่ใบกำกับซ้ำ");
this.invId.Focus();
return;
}
}
int invAmount;
invAmount = int.Parse(invQuantity.Text) * int.Parse(invPrice.Text);
DataGridViewTextBoxColumn column;
column = new DataGridViewTextBoxColumn();
column.DataPropertyName = "เลขที่";
column.HeaderText = "เลขที่";
column.Width = 60;
this.salesOrderView.Columns.Add(column);
column = new DataGridViewTextBoxColumn();
column.DataPropertyName = "รหัสสินค้า";
column.HeaderText = "รหัสสินค้า";
column.Width = 80;
this.salesOrderView.Columns.Add(column);
column = new DataGridViewTextBoxColumn();
column.DataPropertyName = "สินค้า";
column.HeaderText = "สินค้า";
column.Width = 190;
this.salesOrderView.Columns.Add(column);
column = new DataGridViewTextBoxColumn();
column.DataPropertyName = "จำนวน";
column.HeaderText = "จำนวน";
column.Width = 50;
this.salesOrderView.Columns.Add(column);
column = new DataGridViewTextBoxColumn();
column.DataPropertyName = "หน่วยนับ";
column.HeaderText = "หน่วยนับ";
column.Width = 80;
this.salesOrderView.Columns.Add(column);
column = new DataGridViewTextBoxColumn();
column.DataPropertyName = "ราคา";
column.HeaderText = "ราคา";
column.Width = 50;
this.salesOrderView.Columns.Add(column);
column = new DataGridViewTextBoxColumn();
column.DataPropertyName = "จำนวนเงิน";
column.HeaderText = "จำนวนเงิน";
column.Width = 90;
this.salesOrderView.Columns.Add(column);
//dt.Rows.Add(invId.Text, invProductId.Text, invProductName.Text, invQuantity.Text, invUnit.Text, invPrice.Text, invAmount);
this.salesOrderView.Rows.Add(invId.Text, invProductId.Text, invProductName.Text, invQuantity.Text, invUnit.Text, invPrice.Text, invAmount);
//salesOrderView.DataSource = dt;
ClearText();
}
Tag : .NET, Ms Access, Win (Windows App), C#

|
ประวัติการแก้ไข 2012-04-14 15:35:27
|
 |
 |
 |
 |
Date :
2012-04-14 15:34:48 |
By :
DevilMonkeyZ |
View :
1301 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก Code ด้านบนเนี่ยผมว่ามันผิด ขั้นตอนยังไงๆ อยู่นะครับ
ถ้าจะให้ง่ายๆ เราก็เอาค่าที่ได้ไป Check ใน Database เลยจะง่ายกว่าไหมครับ
strOleDb = "SELECT [เลขที่] FROM SalesOrder WHERE [เลขที่] LIKE '%" + invId.Text.trim() + "%';";
จากนั้นก็เช็คว่าพบ Record หรือไม่ ถ้าไม่ก็ค่อย Add และขอแนะนำอีกนิดนะครับ
ชื่อคอลัมน์ ไม่ควรเป็น ภาษาไทย ครับ
|
 |
 |
 |
 |
Date :
2012-04-15 11:34:57 |
By :
smeproject |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|