當前位置:首頁 » 編程語言 » odbcforsqlserver

odbcforsqlserver

發布時間: 2025-02-10 22:26:37

『壹』 VB編程:建立登錄窗口 在線急等!

你題目有點不清,我感覺你應該再加一個label和一個combobox.(用於選擇登錄身份)你有三個表,說明你登錄時的用戶名和密碼應該是取自不同的三個表.
我做過這樣的系統.用的是VB.NET+ACCESS.自己想學的話可以對照來做的.代碼現在告訴你:
Public Class login
Inherits System.Windows.Forms.Form
Public strconn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=exam.mdb"
Public Function GetDataFromDB(ByVal sqlstr As String) As DataSet
objDataSet = New DataSet
objDataSet.Clear()
'實例化一個數據集對象
Try
objConn.Open()
'打開資料庫連接
objDataAdpter = New OleDb.OleDbDataAdapter(sqlstr, objConn)
'將資料庫的數據映射到數據適配器
objDataAdpter.Fill(objDataSet)
'填充數據集的數據
objConn.Close()
'關閉數據連接,這一點很重要
Catch
MsgBox("錯誤號:" & Err.Number & "錯誤描述:" & Err.Description)
objConn.Close()
'發生錯誤時關閉數據連接
End Try
Return objDataSet
objDataSet = Nothing
End Function
Public objConn As New OleDb.OleDbConnection(strconn)
Dim User As String
Dim Password As String
Dim sqlstr As String
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If MsgBox("您真的不登錄考試管理系統嗎?", _
MsgBoxStyle.YesNo + MsgBoxStyle.Question, "退出登錄系統") _
= MsgBoxResult.Yes Then
Application.Exit()
Else
Exit Sub
End If
End Sub
Private Sub Form10_Closing(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles MyBase.Closing
If MsgBox("您真的不登錄考試管理系統嗎?", _
MsgBoxStyle.YesNo + MsgBoxStyle.Question, "退出登錄系統") _
= MsgBoxResult.Yes Then
e.Cancel = False
Else
e.Cancel = True
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
User = Me.TextBox1.Text.Trim
Password = Me.TextBox2.Text.Trim
If Me.ComboBox1.SelectedIndex = 0 Then
sqlstr = "SELECT * FROM userinfo WHERE user_id= " & _
"'" & User & "' AND user_pwd='" & Password & "' or user_name=" & _
"'" & User & "' and user_pwd='" & Password & "'"
Dim objDataRow As DataRow
Try
objDataRow = GetDataFromDB(sqlstr).Tables(0).Rows(0)
Catch
MsgBox("密碼和賬號不符,請重試,並檢查該賬號是否存在。", _
MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "系統登錄失敗")
Me.TextBox2.Text = ""
Exit Sub
End Try
UserName = User
userrole = objDataRow.Item(1)
pepdom = objDataRow.Item(4)
Dim frmmain As New main
frmmain.Show()
Me.Finalize()
ElseIf Me.ComboBox1.SelectedIndex = 1 Then
sqlstr = "SELECT * FROM teacher WHERE teacher_id= " & _
"'" & User & "' AND teacher_pwd='" & Password & "'"
Dim objDataRow As DataRow
Try
objDataRow = GetDataFromDB(sqlstr).Tables(0).Rows(0)
Catch
MsgBox("密碼和賬號不符,請重試,並檢查該賬號是否存在。", _
MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "系統登錄失敗")
Me.TextBox2.Text = ""
Exit Sub
End Try
UserName = User
Userrole = objDataRow.Item(1)
pepdom = objDataRow.Item(4)
Dim frmmain As New main
frmmain.Show()
Me.Finalize()
ElseIf Me.ComboBox1.SelectedIndex = 2 Then
sqlstr = "SELECT * FROM student WHERE student_id= " & _
"'" & User & "' AND student_pwd='" & Password & "'"
Dim objDataRow As DataRow
Try
objDataRow = GetDataFromDB(sqlstr).Tables(0).Rows(0)
Catch
MsgBox("密碼和賬號不符,請重試,並檢查該賬號是否存在。", _
MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "系統登錄失敗")
Me.TextBox2.Text = ""
Exit Sub
End Try
UserName = User
Userrole = objDataRow.Item(1)
pepdom = objDataRow.Item(4)
Dim frmmain As New main
frmmain.Show()
Me.Finalize()
End If
End Sub

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = 13 Then
Me.TextBox2.Focus()
End If
End Sub

Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
If e.KeyCode = 13 Then
Me.Button1.Focus()
End If
End Sub
Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
Me.ComboBox1.SelectedIndex = 0
End Sub

Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
If e.KeyCode = 13 Then
Me.Button1.Focus()
End If
End Sub
End Class

『貳』 金蝶財務軟體中標准憑證引出時出現「ODBC驅動程序不支持所需的屬性」怎麼解決

ODBC驅動程序不支持所需的屬性的解決辦法
用這個連接串StrDSN="driver={SQLserver};server="&StrServer&",1104;uid="&StrUser&";pwd="&StrSaPwd&";database=database
出現下面錯誤

(0x80040E21)

ODBC驅動程序不支持所需的屬性。

用這個連接串

StrDSN="Provider=SQLOLEDB.1;Password=pass;PersistSecurityInfo=True;UserID=id;InitialCatalog=datebase;DataSource="&StrServer&""

錯誤類型:(0x80040E21)
多步OLEDB操作產生錯誤。如果可能,請檢查每個OLEDB狀態值。沒有工作被完成。

默認CommandTimeout=30,修改成:StrDSN="Provider=SQLOLEDB.1;Password=zxc1035;PersistSecurityInfo=True;UserID=zxc;InitialCatalog=database;DataSource="&StrServer&";timeout=2000"
建立和資料庫master的連接

set Conn=Server.CreateObject("ADODB.Connection")

Conn.OpenStrDSN
set Rs=Server.CreateObject("ADODB.RecordSet")
conn.CommandTimeout=3000'注意加了這個RS.openSQL,conn,1,1。

熱點內容
一個小時如何選擇伺服器 發布:2025-02-11 08:58:14 瀏覽:442
網易我的世界伺服器推薦國服 發布:2025-02-11 08:56:34 瀏覽:241
電視父母鎖屏密碼應該會是什麼 發布:2025-02-11 08:36:42 瀏覽:891
梅花適合用哪些植物進行配置 發布:2025-02-11 08:30:54 瀏覽:252
安卓手機如何像蘋果一樣彈窗 發布:2025-02-11 08:26:33 瀏覽:911
壓縮文件掃碼 發布:2025-02-11 08:20:55 瀏覽:257
小米5安卓70怎麼分屏 發布:2025-02-11 08:00:58 瀏覽:139
訪問二維碼 發布:2025-02-11 08:00:11 瀏覽:882
騰訊雲香港伺服器搭建 發布:2025-02-11 07:53:44 瀏覽:794
eclipsejava編譯器 發布:2025-02-11 07:53:09 瀏覽:495