 |
|
VB 2010 กับ Access 2007 บันทึกข้อมูลแล้วไม่ลงฐานข้อมูล |
|
 |
|
|
 |
 |
|
เอาโค๊ดมาดูหน่อยครับ พอดีที่ทำงาน บล๊อค Youtube อะครับ
|
 |
 |
 |
 |
Date :
2014-05-29 11:06:27 |
By :
CPU4Core |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'TelbookDataSet.Table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.TelbookDataSet.Table1)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Table1BindingSource.AddNew()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Table1BindingSource.RemoveCurrent()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Table1BindingSource.EndEdit()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Table1TableAdapter.Update(TelbookDataSet.Table1)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Table1BindingSource.MovePrevious()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Table1BindingSource.MoveNext()
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Me.Close()
End Sub
End Class
นี่ครับง่ายๆ พอบันทึกมันก็ใส่ลงฐานข้อมูลให้ครับ แต่พอปิดเปิดใหม่ไม่ลงฐานข้อมูล Access
|
 |
 |
 |
 |
Date :
2014-05-29 11:13:07 |
By :
akarawoot |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่บันทึกลง Access อ่ะครับ พอปิดโปรแกรมแล้วลองไปเปิด access ดูกลับพบว่าข้อมูลเหมือนเดิม ไม่ได้บันทึกใหม่เลย
|
 |
 |
 |
 |
Date :
2014-05-29 11:17:57 |
By :
Mr.Beer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมีตัวอย่างนึงเป็นการ ใช้ VB2010 + MSACCESS2007
เหมือนกับของคุณ แต่มันมีแค่ TEXTBOX กับ ปุ่มกด อย่างละอัน
พอดีผมทำให้น้องคนนึงดูตัวอย่างอะครับ
ลองโหลดไปศึกษาดูนะครับ
ปล มันเป็นไฟล์ proj ของ VB เลยะนะครับ
http://www.upload-thai.com/dl/275a8eec03178287a924aab65172f58b
ปล ผมไม่ค่อยได้เขียนตามวิธีที่คุณถามอะครับ เลยตอบไม่ได้ แหะ ๆ
|
 |
 |
 |
 |
Date :
2014-05-29 11:25:21 |
By :
CPU4Core |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณสำหรับแนวทางครับ แต่ผมยังคล่องใจระหว่างเลือกฐานข้อมูล MySQL ดี หรือ Access ดีครับ
จะใช้ต่อไป อันไหนอนาคตสดใสกว่า
|
 |
 |
 |
 |
Date :
2014-05-29 13:09:37 |
By :
akarawoot |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าอยากจะ ใช้เป็นแนว Server หลาย ๆเครื่องใช้ ฐานเดียวกัน ก็ MySQL
แต่ถ้า StandAlone ก็ Access ก็ได้ครับ
|
 |
 |
 |
 |
Date :
2014-05-29 13:13:58 |
By :
CPU4Core |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เกิดจากอะไร เป็นเหมือนกัน
|
 |
 |
 |
 |
Date :
2016-10-30 01:09:23 |
By :
vinai55 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูจากคำสั่งจากปุ่มต่าง ๆ แล้ว ... มันก็ไม่น่าที่จะบันทึกข้อมูลลงไปใน Database ได้นะครับ เพราะทุกปุ่ม ดูแล้ว ยังขาดคำสั่ง เช่น
Table1TableAdapter.Name = textbox1.text
Table1TableAdapter.SurName = textbox2.text
Table1TableAdapter.Id = textbox3.text
Table1TableAdapter.Address = textbox4.text
Table1TableAdapter.Tel = textbox5.text
ประมาณนี้ครับ เพราะว่าในการบันทึกข้อมูลแบบนี้คุณต้องกดปุ่ม 2 ปุ่มเพื่อรับข้อมูลคือ
Button1_Click เพราะมีคำสั่ง .AddNew
และ Button3_Click เพราะมีคำสั่ง .Update
จริง ๆ แล้วน่าจะเป็นคำสั่งที่อยู่ในปุ่มเดียวกันดังนี้ครับ
Table1BindingSource.AddNew
Table1TableAdapter.Name = textbox1.text
Table1TableAdapter.SurName = textbox2.text
Table1TableAdapter.Id = textbox3.text
Table1TableAdapter.Address = textbox4.text
Table1TableAdapter.Tel = textbox5.text
Table1BindingSource.Update
|
 |
 |
 |
 |
Date :
2016-10-30 06:51:02 |
By :
ละอ่อน |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code
Imports System.Data.SqlClient
Public Class frm_add
Private Sub btt_add1_Click(sender As Object, e As EventArgs) Handles btt_add1.Click
Dim cn As New SqlConnection("Server=MR-TFP3T1B2E2IJ\SQLEXPRESSS; Database = 603data; Integrated Security=true")
Dim sql As String
Dim cmd As New SqlCommand
If txt_add_id.Text = "" Or txt_add_number.Text = "" Or txt_add_sex.Text = "" Or txt_add_name.Text = "" Or txt_add_lastname.Text = "" Or txt_add_nickname.Text = "" Or txt_add_birthday.Text = "" Or txt_add_blood.Text = "" Or txt_add_nationality.Text = "" Or txt_add_origin.Text = "" Or txt_add_religion.Text = "" Or txt_add_sex2.Text = "" Or txt_add_weight.Text = "" Or txt_add_height.Text = "" Or txt_add_id13.Text = "" Or txt_add_address.Text = "" Or txt_add_tumbol.Text = "" Or txt_add_district.Text = "" Or txt_add_province.Text = "" Or txt_add_zipcode.Text = "" Or txt_add_numberphone.Text = "" Or txt_add_motto.Text = "" Or txt_add_email.Text = "" Or txt_add_facebook.Text = "" Or txt_add_lineee.Text = "" Or txt_add_ig.Text = "" Then
MessageBox.Show("กรุณากรอกข้อมูลให้ครบด้วยครับ..", "คำเตือน", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
Else
MessageBox.Show("คุณต้องการบันทึกข้อมูลใช่หรือไม่?", "ยืนยัน", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
sql = "insert into 603tb(id,number,sex,name,lastname,nickname,birthday,blood,nationality,origin,religion,sex2,weight,height,id13,address,tumbol,district,province,zipcode,phonenumber,motto,email,facebook,line,ig)"
sql &= " values ( '" & txt_add_id.Text & "','" & txt_add_number.Text & "','" & txt_add_sex.Text & "','" & txt_add_name.Text & "','" & txt_add_lastname.Text & "','" & txt_add_nickname.Text & "','" & txt_add_birthday.Text & "','" & txt_add_blood.Text & "','" & txt_add_nationality.Text & "','" & txt_add_origin.Text & "','" & txt_add_religion.Text & "','" & txt_add_sex2.Text & "','" & txt_add_weight.Text & "','" & txt_add_height.Text & "','" & txt_add_id13.Text & "','" & txt_add_address.Text & "','" & txt_add_tumbol.Text & "','" & txt_add_district.Text & "','" & txt_add_province.Text & "','" & txt_add_zipcode.Text & "','" & txt_add_numberphone.Text & "','" & txt_add_motto.Text & "','" & txt_add_email.Text & "','" & txt_add_facebook.Text & "','" & txt_add_lineee.Text & "','" & txt_add_ig.Text & "')"
With cmd
.CommandType = CommandType.Text
.CommandText = sql
.Connection = cn
.ExecuteNonQuery()
End With
MessageBox.Show("เพิ่มข้อมูลเรียบร้อยแล้ว", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub btt_add2_Click(sender As Object, e As EventArgs) Handles btt_add2.Click
frm_main.Show()
Me.Close()
End Sub
End Class
ช่วยหน่อยค่ารันไม่ผ่านสักที ติดตรง .ExecuteNonQuery()
|
 |
 |
 |
 |
Date :
2017-03-11 02:31:47 |
By :
ช่วยหน่อยต้องส่งงานพุ่งนี้แล้ว |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Error ว่า
|
 |
 |
 |
 |
Date :
2017-03-11 13:07:12 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|