|
|
|
ช่วยด้วยครับไม่สามารถ UPDATE ค่าใน windows form application |
|
|
|
|
|
|
|
มันติดอะไรหรอครับ พอดีมือใหม่ครับ แนะนำด้วยครับ
Code (C#)
using System.Data.SqlClient;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
SqlConnection CN = new SqlConnection("Data Source=.;Initial Catalog=PROJECT-FERN;User ID=sa;Password=12345");
public Form1()
{
InitializeComponent();
}
DataView DV;
SqlDataAdapter DAProduct;
private void ShowProduct()
{
if (DS.Tables.Contains("JoinProduct"))
DS.Tables.Remove("JoinProduct");
string SQL = "Select*from Product inner join Category on Product.ProCat = Category.ProCat";
DAProduct = new SqlDataAdapter(SQL, CN);
DAProduct.Fill(DS, "JoinProduct");
DV = new DataView(DS.Tables["JoinProduct"]);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = DV;
}
SqlDataAdapter DACategory;
private void ShowCategory()
{
String SQL = "Select*from Category";
DACategory = new SqlDataAdapter(SQL,CN);
DACategory.Fill(DS, "Cat");
comboBox1.DataSource = DS.Tables["Cat"];
comboBox1.DisplayMember = "CatName";
comboBox1.ValueMember = "ProCat";
}
DataSet DS = new DataSet();
SqlDataAdapter DA;
private void Form1_Load(object sender, EventArgs e)
{
CN.Open();
string SQL = "Select * from Product";
DA = new SqlDataAdapter(SQL,CN);
SqlCommand CM = new SqlCommand(SQL,CN);
DA.Fill(DS,"Pro");
ShowProduct();
ShowCategory();
this.textBox3.Text = DateTime.Today.ToString("dd/MM/yyyy");
this.textBox2.Text = Program.EmpName;
}
private void button1_Click(object sender, EventArgs e)
{
DataRow DR = DS.Tables["Pro"].NewRow();
DR["ProID"] = textBox1.Text;
DR["ProName"] = textBox2.Text;
DR["ProCat"] = comboBox1.SelectedValue;
DR["ProTime"] = textBox3.Text;
if (radioButton1.Checked)
DR["ProSta"] = "หมด";
else
DR["ProSta"] = "ไม่หมด";
DS.Tables["Pro"].Rows.Add(DR);
DA.Update(DS,"Pro");
ShowProduct();
ShowCategory();
}
private void button2_Click(object sender, EventArgs e)
{
DataRow[] DR = DS.Tables["Pro"].Select("ProID="+ textBox1.Text);
DR[0]["ProName"] = textBox2.Text;
DR[0]["ProCat"] = comboBox1.SelectedValue;
DR[0]["ProTime"] = textBox3.Text;
if (radioButton1.Checked)
DR[0]["ProSta"] = "หมด";
else
DR[0]["ProSta"] = "ไม่หมด";
}
int i = 0;
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
i = e.RowIndex;
if (i >= 0)
{
textBox1.Text = DV[i]["ProID"].ToString();
textBox2.Text = DV[i]["ProName"].ToString();
comboBox1.Text = DV[i]["ProCat"].ToString();
textBox3.Text = DV[i]["ProTime"].ToString();
if (DV[i]["ProSta"].ToString() == "หมด")
radioButton1.Checked = true;
else
radioButton2.Checked = true;
}
}
}
}
Tag : .NET, Win (Windows App), C#
|
|
|
|
|
|
Date :
2015-05-17 06:12:22 |
By :
aarayaing |
View :
787 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่ค่อยเข้าใจอะครับถ้าจะแก้ต้องทำวิธีไหนครับ
คือจะเพิ่มแล้วบันทึกดาต้าเบสอะครับ
|
ประวัติการแก้ไข 2015-05-18 00:25:52
|
|
|
|
Date :
2015-05-18 00:23:50 |
By :
aarayaing |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|