Imports System.Data.SqlClient
Imports System.Data.Odbc
Imports System.Data
Imports System.Configuration
Imports System.Data.OleDb
Public Class Form2
Dim g_login As String
Dim g_user As String
Dim g_password As String
Dim Sql As String
Dim myCom As New SqlCommand
Dim myDa As SqlDataAdapter
Dim myDs As New DataSet
Dim myDr As SqlDataReader
Dim myTs As SqlTransaction
' Dim strCon As String = ConfigurationManager.ConnectionStrings("workproject.My.MySettings.myDB").ConnectionString
Dim strSql As String
Dim ID As String
Dim bb As Integer
Dim sqlAD As String
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Dim com3 As SqlConnection
' connetionstring = "Data Source =SPAREIT-02; Initial Catalog = test;User ID= " & MaskedTextBox1.Text & ";Password=" & MaskedTextBox2.Text & "")
' MessageBox.Show(" เชื่อมต่อได้แล้ว ")
' MessageBox.Show(" เชื่อมต่อไม่ได้ ")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Dim ds As String
'Using connection = New SqlConnection("Data Source =SPAREIT-02; Initial Catalog = test;User ID=SA;Password=pong1234")
Dim connectionString As String = " SERVER=SPAREIT-02; DATABASE=test; user=pong; Password=pong1234 ;User ID= " & MaskedTextBox1.Text & ";user =" & MaskedTextBox2.Text & ";Password=" & MaskedTextBox3.Text & ""
' com3 = New SqlConnection(connetionstring)
' Dim da As OdbcDataAdapter
Dim conn As New OdbcConnection(connectionString)
' Dim ds As DataSet
g_login = MaskedTextBox1.Text
g_user = MaskedTextBox2.Text
g_password = MaskedTextBox3.Text
ID = "insert"
Try
MaskedTextBox1.Enabled = True
MaskedTextBox2.Enabled = True
MaskedTextBox3.Enabled = True
MaskedTextBox1.Clear()
MaskedTextBox2.Clear()
MaskedTextBox3.Clear()
MessageBox.Show(" เพิ่มได้ ")
Catch ex As Exception
MessageBox.Show(" เพิ่มไม่ได้ ")
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim com3 As SqlConnection
Dim cm As New SqlCommand
' sqlADD = "INSERT INTO test (id,user,password)"
' sqlADD = "VALUES ('" & MaskedTextBox1.Text & "','" & MaskedTextBox2.Text & "','" & MaskedTextBox3.Text & ")"
Dim connectionString As String = " SERVER=SPAREIT-02; DATABASE=test; user=pong; Password=pong1234 ;User ID= " & MaskedTextBox1.Text & ";user =" & MaskedTextBox2.Text & ";Password=" & MaskedTextBox3.Text & ""
'ใช้ oledbcommand ในการเพิ่มข้อมูล
If MessageBox.Show("คุณต้องการเพิ่มรายชื่อใหม่ใช่หรือไม่?", "ยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
With cm
.CommandType = CommandType.Text
.CommandText = sqlAD
.Connection =
.ExecuteNonQuery()
End With
MessageBox.Show("เพิ่มรายชื่อพนักงานแล้ว", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
MaskedTextBox1.Clear()
MaskedTextBox2.Clear()
MaskedTextBox3.Clear()
End If
End Sub
End Class
Tag : MySQL, Ms SQL Server 2005, Ms SQL Server 2008, Web (ASP.NET), Web Service
Imports System.Data.SqlClient
Imports System.Data
Imports System.Data.OleDb
Imports System
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim con As New SqlClient.SqlConnection
Dim strCon As String = "Data Source=SPAREIT-02;Initial Catalog=test ;user id = sa ; password= pong1234 ;Integrated Security=SSPI;Connection Timeout=10;" 'NT Authentication
Dim strCommand As String = "SELECT * FROM setid"
Dim command As SqlCommand
Dim da As SqlDataAdapter
Dim dt As New DataTable
Try
con.ConnectionString = strCon
command = New SqlCommand(strCommand, con)
command.CommandTimeout = 3000
MessageBox.Show("เชื่อมต่อได้แล้ว")
da = New SqlDataAdapter(command)
da.Fill(dt)
MsgBox(dt.Rows.Count.ToString())
MsgBox(dt.Columns.Count.ToString())
Catch ex As Exception
MessageBox.Show(ex.Message, "Error")
Finally
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strid As String = MaskedTextBox1.Text
Dim strun As String = MaskedTextBox1.Text
Dim strpw As String = MaskedTextBox1.Text
Dim connection As SqlConnection = Nothing
Dim objcmd As OleDbCommand = Nothing
Dim strcon As String, strSql As String
strcon = "Data Source=SPAREIT-02;Initial Catalog=test ;user id = sa ; password= pong1234 ;Integrated Security=SSPI;Connection Timeout=10;"
connection = New SqlConnection(strcon)
connection.ConnectionString = strcon
connection.Open()
strSql = "insert into user (id,username, password )values(?,?,?)"
objcmd = New OleDbCommand(strSql)
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@username", strid))
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@username", strun))
objcmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@username", strpw))
objcmd.ExecuteNonQuery()
connection.Close()
' Response.Write()
End Sub
End Class