关于vb.net的数据连接,急
我是初学者,最近要交一份期末作业,做了个小系统,用到了数据库,我是用ACCESS建的。。做好了 ,系统没提示错误,但每当运行到 有关连接到数据库的 时候 就会跳出个提示“在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: SQL 网络接口, error: 26 - 定位指定的服务器/实例时出错)”
这是什么原因呢。是不是 代码用的 是SQL建的数据库?还是有什么其他的问题。
忘能者帮忙,万分感谢,明天就要交作业了。。有好心人,可以加下我Q,帮我改下。。。太感谢了。。我的qq:1511272703
一下是一个界面的代码:
Imports System.Data
Imports System.Data.SqlClient
Public Class 员工档案查询
Inherits System.Windows.Forms.Form
Dim strconn As String = "Data Source=F:\10学校\vb\期末\人事管理系统\人事管理系统\员工基本信息管理系统.mdb;initial catalog=员工基本信息管理系统;"
Dim objds As New Data.DataSet
Dim objda As SqlClient.SqlDataAdapter
Dim bingpage As BindingManagerBase
Dim strsql As String
Dim cmd As SqlCommandBuilder
Dim dt As New DataTable
Private Sub 员工档案查询_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: 这行代码将数据加载到表“员工基本信息管理系统DataSet.员工档案表”中。您可以根据需要移动或移除它。
Me.员工档案表TableAdapter.Fill(Me.员工基本信息管理系统DataSet.员工档案表)
strsql = "select * from 员工档案表"
objda = New SqlClient.SqlDataAdapter(strsql, strconn)
objda.Fill(objds, "员工档案表") \\ 运行该界面的时候,缓冲了一会儿 就会跳到编码界面,这句话变黄色,并提示上面的错误。
DataGridView1.DataSource = objds.Tables("员工档案表")
bingpage = Me.BindingContext(objds, "员工档案表")
TextBox1.DataBindings.Add(New Binding("text", objds, "员工档案表.员工号"))
TextBox2.DataBindings.Add(New Binding("text", objds, "员工档案表.姓名"))
TextBox3.DataBindings.Add(New Binding("text", objds, "员工档案表.性别"))
TextBox4.DataBindings.Add(New Binding("text", objds, "员工档案表.民族"))
TextBox5.DataBindings.Add(New Binding("text", objds, "员工档案表.出生日期"))
TextBox5.Text = CDate(TextBox5.Text)
TextBox6.DataBindings.Add(New Binding("text", objds, "员工档案表.政治面貌"))
TextBox7.DataBindings.Add(New Binding("text", objds, "员工档案表.身份证号"))
TextBox8.DataBindings.Add(New Binding("text", objds, "员工档案表.学历"))
TextBox9.DataBindings.Add(New Binding("text", objds, "员工档案表.毕业院校"))
TextBox10.DataBindings.Add(New Binding("text", objds, "员工档案表.部门"))
TextBox11.DataBindings.Add(New Binding("text", objds, "员工档案表.职称"))
TextBox12.DataBindings.Add(New Binding("text", objds, "员工档案表.工资"))
TextBox13.DataBindings.Add(New Binding("text", objds, "员工档案表.录取时间"))
TextBox13.Text = CDate(TextBox13.Text)
TextBox14.DataBindings.Add(New Binding("text", objds, "员工档案表.合同有效期"))
TextBox14.Text = CDate(TextBox14.Text)
TextBox15.DataBindings.Add(New Binding("text", objds, "员工档案表.电话号码"))
TextBox16.DataBindings.Add(New Binding("text", objds, "员工档案表.备注"))
ComboBox1.Items.Add("员工号")
ComboBox1.Items.Add("姓名")
ComboBox1.Items.Add("部门")
ComboBox1.Items.Add("出生日期")
TextBox1.ReadOnly = True
TextBox2.ReadOnly = True
TextBox3.ReadOnly = True
TextBox4.ReadOnly = True
TextBox5.ReadOnly = True
TextBox6.ReadOnly = True
TextBox7.ReadOnly = True
TextBox8.ReadOnly = True
TextBox9.ReadOnly = True
TextBox10.ReadOnly = True
TextBox11.ReadOnly = True
TextBox12.ReadOnly = True
TextBox13.ReadOnly = True
TextBox14.ReadOnly = True
TextBox15.ReadOnly = True
TextBox16.ReadOnly = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
bingpage.Position = 0
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
bingpage.Position = bingpage.Position - 1
If bingpage.Position <> 1 Then
Button1.Enabled = True
Button2.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
Else
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
bingpage.Position = bingpage.Position + 1
If bingpage.Position <> bingpage.Count - 1 Then
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
Else
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = False
Button4.Enabled = False
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
bingpage.Position = bingpage.Count - 1
Button1.Enabled = True
Button2.Enabled = True
Button3.Enabled = False
Button4.Enabled = False
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
objds.Clear()
If ComboBox1.Text = "" Or TextBox17.Text = "" Then
MessageBox.Show("请输入查询条件!")
Exit Sub
Else
strsql = "select * from 员工档案表 where " & Trim(ComboBox1.Text) & "=" & "'" & Trim(TextBox17.Text) & "'"
objda = New SqlClient.SqlDataAdapter(strsql, strconn)
objda.Fill(dt)
cmd = New SqlCommandBuilder(objda)
DataGridView1.DataSource = dt
If dt.Rows.Count = 0 Then
MessageBox.Show(" 不存在该员工的信息!")
Exit Sub
End If
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
objds.Clear()
strsql = "select * from 员工档案表"
objda = New SqlClient.SqlDataAdapter(strsql, strconn)
objda.Fill(objds, "员工档案表")
DataGridView1.DataSource = objds.Tables("员工档案表")
End Sub
End Class
[ 本帖最后由 sugala 于 2010-6-24 15:57 编辑 ]