|
 |
|
อยากได้ตัวอย่างโค๊ด C# ที่ต่อกับ MySQL ของ XAMPP |
|
 |
|
|
 |
 |
|
ตามหัวข้อข้างบนครับ ขอบคุณล่วงหน้าครับผม ตอนนี้โค๊ดผมทำได้แค่นี้ครับ ยังงงไปต่อไม่ถูกครับ
Code (C#)
String MyConectionstring = "Server=localhost;Database=db2;";
private void Form2_Load(object sender, EventArgs e)
{
MySqlConnection con = new MySqlConnection(MyConectionstring);
try
{
con.Open();
MessageBox.Show("connected");
}
catch
{
MessageBox.Show("disconnect");
}
}
private void button1_Click(object sender, EventArgs e)
{
String date = dateTimePicker1.Text;
String re_date = dateTimePicker2.Text;
String re_p = null;
String pay=null;
//recive
if (radioButton1.Checked)
re_p = "this place";
else if (radioButton2.Checked)
re_p = "Fax";
else
re_p = "post";
//Payment
if (comboBox1.SelectedIndex == 0)
pay = "money";
else if (comboBox1.SelectedIndex == 1)
pay = "receipt";
else if (comboBox1.SelectedIndex == 2)
pay = "transfer";
else if (comboBox1.SelectedIndex == 3)
pay = "unpaid";
//command insert
cmd.CommandText = "insert into Profile values('" + ID.Text.Trim() + "','" + date + "','" + name.Text.Trim() + "','" + adr.Text.Trim() + "','" + tel.Text.Trim() + "','" + fax.Text.Trim() + "','" + mail.Text.Trim() + "','" + obj.Text.Trim() + "','" + num.Text.Trim() + "','" + syn.Text.Trim() + "','" + namet.Text.Trim() + "')";
//cmd.Connection = con; ตรงนี้ error ครับ
cmd.ExecuteNonQuery();
cmd.CommandText = "insert into Data values('" + ID.Text.Trim() + "','" + mo.Text.Trim() + "','" + pro.Text.Trim() + "','" + fat.Text.Trim() + "','" + fiber.Text.Trim() + "','" + fiberh.Text.Trim() + "','" + ash.Text.Trim() + "','" + asha.Text.Trim() + "','" + cal.Text.Trim() + "','" + phos.Text.Trim() + "','" + ndf.Text.Trim() + "','" + adf.Text.Trim() + "','" + adfa.Text.Trim() + "','" + en.Text.Trim() + "','" + sodium.Text.Trim() + "','" + pow.Text.Trim() + "','" + am.Text.Trim() + "','" + tan.Text.Trim() + "','" + uri.Text.Trim() + "','" + me.Text.Trim() + "')";
//cmd.Connection = con; ตรงนี้ error ครับ
cmd.ExecuteNonQuery();
cmd.CommandText = "insert into Re values('" + ID.Text.Trim() + "','" + re_p + "','" + post.Text.Trim() + "','" + re_date + "','" + recieve.Text.Trim() + "','" + sent.Text.Trim() + "','" + pay + "','" + money.Text.Trim() + "')";
//cmd.Connection = con; ตรงนี้ error ครับ
cmd.ExecuteNonQuery();
MessageBox.Show("complete");
}
Tag : .NET, MySQL, C#

|
|
 |
 |
 |
 |
Date :
2014-07-09 15:01:20 |
By :
pcbimon |
View :
1136 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันใช้คำสั่ง Connector ของ MySqlConnection ครับ จะเขียนด้วยอะไ่รก็ไม่ต่างกันครับ
ASP.NET MySql.Data.MySqlClient
ASP.NET MySQL (MySql.Data.MySqlClient)
|
 |
 |
 |
 |
Date :
2014-07-09 16:29:32 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ แล้วจะลองดูน่ะครับ
|
 |
 |
 |
 |
Date :
2014-07-09 17:45:07 |
By :
pcbimon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|