我用vs.net2005做开发工具 在连接数据库上老是有小小的错误请高手们指点指点 写出完整的连接语句让我参考一下sql和access都可以
我写的是:(Labmanage是我建立的sql数据库,Adamin是表名,Id和Pwd是自段)他提示我连接错误,why
Dim myconn As New SqlClient.SqlConnection("data source=localhost;initial catalog=LabManage")
Dim mycmd As SqlClient.SqlCommand
Dim adaminsql As String
adaminsql = "select * from Adamin where Id='" + TextBox1.Text + "'"
Try
mycmd = New SqlClient.SqlCommand(adaminsql, myconn)
myconn.Open()
Dim tbl1 As New DataTable
Dim adp1 As New SqlClient.SqlDataAdapter(adaminsql, myconn)
adp1.Fill(tbl1)
If tbl1.Rows.Count <= 0 Then
MessageBox.Show("用户名错误!")
Else
If tbl1.Rows(0).Item("Pwd").ToString.Trim = TextBox2.Text Then
MessageBox.Show("正确")
Else
MessageBox.Show("密码输入错误!")
End If
End If
參考答案:<%@ import namespace=system.data %>
<%@ import namespace=system.data.sqlclient %>
<script language=vb runat=server>
sub page_load(sender as object , e as eventargs)
dim conn as new sqlconnection
conn.connectionstring = "server=(local);user id=sa;pwd=;database=库名" '用户为sa密码为空
conn.open()
dim sql as string = "select * from Adamin where Id='" + TextBox1.Text + "'"
dim objcmd as new sqlcommand(sql,conn)
dim objreader as sqldatareader = objcmd.executereader()
if objreader.read() then
response.write("正确")
else
response.write("用户名不正确")
end if
objreader.close()
conn.close()
这里只判断了用户名.可根据实际加上密码.