vb.net实现连接线的简单介绍

vb.net的数据库连接1·绑定数据源来进行连接
2.用代码连接
先到数据库建立一个数据库和相应的表
连接数据库的代码:
Dim str As String = "Data Source=服务器名;Initial Catalog=数据库名;Persist Security Info=True;User ID=;Password="
dim conn As SqlClient.SqlConnection
try
conn = New SqlClient.SqlConnection
conn.ConnectionString = str
conn.Open()
Return True
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try
登录代码:Dim str As String = "Data Source=服务器名;Initial Catalog=数据库名;Persist Security Info=True;User ID=;Password="
dim conn As SqlClient.SqlConnection
conn = New SqlClient.SqlConnection
conn.ConnectionString = str
conn.Open()
sqlstr = "Select * From Amd Where AmdName='"TextBox1.Text"' And AmdPwd = '"TextBox2.Text"'"
Dim sqlcmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(sqlstr, conn)
Dim dr As SqlClient.SqlDataReader
dr = sqlcmd.ExecuteReader
If dr.Read = True Then'判断一条记录为真
kf.Show() '显示下个窗体
Me.Hide() ’隐藏当前窗体
Else
MessageBox.Show("输入信息有误!", "提示")
TextBox1.Text = ""
TextBox2.Text = ""
End If
SQL Server用VB.NET 2010怎麼连线?Data Source=(local)\NetSDK;Initial Catalog=北风贸易;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;
你试看这个代码 。。。
用vb.net实现网络通信用 vb.net socket通信
Dim th As Threading.Thread
2Dim tcpl As System.Net.Sockets.TcpListener
3
4Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
5th = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf MyListen))
6th.Start()
7End Sub
8
9Public Sub SendMessage()Sub SendMessage(ByVal IP As String, ByVal SendMsg As String)
10Try
11If IP"" Then
12Dim tcpc As New System.Net.Sockets.TcpClient(IP, 5656)
13Dim tcpStream As Net.Sockets.NetworkStream = tcpc.GetStream
14Dim reqStream As New IO.StreamWriter(tcpStream)
15reqStream.Write(SendMsg)
16reqStream.Flush()
17tcpStream.Close()
18tcpc.Close()
19End If
20Catch ex As Exception
21MsgBox(ex.Message.ToString)
22End Try
23End Sub
24Private Sub MyListen()Sub MyListen()
25Try
26Dim ipAddress As System.Net.IPAddress = System.Net.Dns.Resolve(System.Net.Dns.GetHostName).AddressList(0)
27tcpl = New System.Net.Sockets.TcpListener(ipAddress, 5656)
28tcpl.Start()
29While True
30Dim s As System.Net.Sockets.Socket = tcpl.AcceptSocket()
31Dim MyBuffer(1024) As Byte
32Dim i As Integer
33i = s.Receive(MyBuffer)
34If i0 Then
35Dim lstrRec As String
36Dim j As Integer
37For j = 0 To i - 1
38TextBox1.Text += Chr(MyBuffer(j))","
39Next
40End If
41End While
42Catch ex As Exception
43MsgBox(ex.Message.ToString)
44End Try
45End Sub
46
47Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
48SendMessage("192.168.0.61", TextBox2.Text)
49End Sub
【vb.net实现连接线的简单介绍】vb.net实现连接线的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于、vb.net实现连接线的信息别忘了在本站进行查找喔 。

    推荐阅读