|
|
|
มีปัญหาเรื่องการบันทึกข้อมูลลง database จาก textbox ครับ c# access |
|
|
|
|
|
|
|
แบบนี้รันผ่านครับ
Code (C#)
command.CommandText = "insert into Student (Title,Fname,Lname,Bev) values('"+textBox1.Text.Trim()+ "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "','" + textBox4.Text.Trim() + "') ";
พอเพิ่มอีกแค่ 1 คอลัม ก็ERROR เลยครับ
Code (C#)
command.CommandText = "insert into Student (Title,Fname,Lname,Bev,Day) values('"+textBox1.Text.Trim()+ "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "','" + textBox4.Text.Trim() + "','" + textBox5.Text.Trim() + "') ";
ด้านล่างเป็นโค้ดทั้งหมดครับ
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SchoolApp
{
public partial class Form1 : Form
{
private OleDbConnection connection = new OleDbConnection();
public Form1()
{
InitializeComponent();
try {
connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\HANNIBAN\Desktop\SchoolApp\SchoolApp\bin\Debug\Database.mdb";
connection.Open();
label1.Text = "Connection Success";
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
}
private void btnSave_Click(object sender, EventArgs e)
{
try {
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "insert into Student (Title,Fname,Lname,Bev) values('"+textBox1.Text.Trim()+ "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "','" + textBox4.Text.Trim() + "') ";
command.ExecuteNonQuery();
MessageBox.Show("DATA SAVED");
connection.Close();
}
catch(Exception ex)
{
MessageBox.Show("Eror"+ex);
}
}
}
}
Tag : .NET, Ms Access, C#
|
ประวัติการแก้ไข 2015-10-26 01:47:17
|
|
|
|
|
Date :
2015-10-26 01:44:36 |
By :
pkraiya |
View :
927 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลอง
convert.todatetime(textBox5.Text)
รึไรประมาณนั้นดูครับ
|
|
|
|
|
Date :
2015-10-26 07:52:48 |
By :
lamaka.tor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|