 |
|
สอบถามการเพิมข้อมูลจาก VB.Net ลง SQL server 2008ค่ะ โค้ดไม่เออเร่อแต่ข้อมูลไม่เข้า Databaseให้ |
|
 |
|
|
 |
 |
|
Code (VB.NET)
Imports System.Data.SqlClient
Public Class frmUserRegister
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
End Sub
Private Sub frmUserRegister_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim strsql As String
con.ConnectionString = "Data Source=localhost; Initial Catalog=ProjectOCR; Integrated Security= true"
cmd.Connection = con
con.Open()
strsql = "INSERT INTO Teacher(teac_id, teac_name, teac_username, teac_password, answer)"
strsql &= "VALUES('" & txtTeacID.Text & "','" & txtTeacName.Text & "','" & txtTeacUsername.Text & "','" & txtTeacPassword.Text & "','" & txtTeacAnswer.Text & "')"
With cmd
.Connection = con
.CommandText = strsql
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
End Sub
End Class
|
 |
 |
 |
 |
Date :
2015-01-27 00:29:59 |
By :
Preeyapan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code
Imports System.Data.SqlClient
Public Class frmUserRegister
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim strsql As String
con.ConnectionString = "Data Source=localhost; Initial Catalog=ProjectOCR; Integrated Security= true"
cmd.Connection = con
con.Open()
strsql = "INSERT INTO Teacher(teac_id, teac_name, teac_username, teac_password, answer)"
strsql &= "VALUES('" & txtTeacID.Text & "','" & txtTeacName.Text & "','" & txtTeacUsername.Text & "','" & txtTeacPassword.Text & "','" & txtTeacAnswer.Text & "')"
With cmd
.Connection = con
.CommandText = strsql
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
End Sub
Private Sub frmUserRegister_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
มันอยู่ใน Event ของ btnSubmit_Click หรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2015-01-27 09:26:13 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|