帮忙看下datagrid为什么不能显示数据
Public Class Form1
Inherits System.Windows.Forms.Form
Dim objConnection As SqlConnection = New SqlConnection("server=(local);database=face360;user id=wjf;password=wjf123")
Dim objDataAdapter As New SqlDataAdapter()
Dim objDataSet As DataSet = New DataSet()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
objDataAdapter.SelectCommand = New SqlCommand()
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter.SelectCommand.CommandText = "select user_id,user_pw,user_name from anyface_user"
objDataAdapter.SelectCommand.CommandType = CommandType.Text
objConnection.Open()
objDataAdapter.Fill(objDataSet, "anyface_user")
objConnection.Close()
grdAuthorTitles.DataSource = objDataSet
grdAuthorTitles.DataMember = "anyface_user"
objDataAdapter = Nothing
objConnection = Nothing
End Sub
End Class
Try
Dim objConnection As SqlConnection = New SqlConnection("server=rhkf004;database=u_zl;user id=sa;password=123")
Dim objDataAdapter As New SqlDataAdapter()
Dim objDataSet As DataSet = New DataSet()
objConnection.Open()
objDataAdapter.SelectCommand = New SqlCommand()
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter.SelectCommand.CommandText = "select item_id,item_Nm from u_item"
objDataAdapter.SelectCommand.CommandType = CommandType.Text
objDataAdapter.Fill(objDataSet, "u_item")
DG.DataSource = objDataSet
DG.DataMember = "u_item"
objConnection.Close()
Catch ex As Exception
Msbox.Show(ex.ToString)
End Try
Public Class Form1
Inherits System.Windows.Forms.Form
Dim objConnection As SqlConnection = New SqlConnection("server=(local);database=face360;user id=wjf;password=wjf123")
Dim objDataAdapter As New SqlDataAdapter()
Dim objDataSet As DataSet = New DataSet()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
objDataAdapter.SelectCommand = New SqlCommand()
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter.SelectCommand.CommandText = "select user_id,user_pw,user_name from anyface_user"
objDataAdapter.SelectCommand.CommandType = CommandType.Text
objConnection.Open()
Dim objdatatable As DataTable = New DataTable()'建立新表
objDataAdapter.Fill(objdatatable )
objConnection.Close()
grdAuthorTitles.DataSource = objdatatable ‘绑定数据
objDataAdapter = Nothing
objConnection = Nothing
End Sub
End Class