vb.net的DataGridView数据绑定

数据库查询语句里有COUNT、SUM、AVG、MAX、MIN这样的聚合函数,应该如何把这类的项绑定到VB.NET的DataGridView控件中?

第1个回答  2015-06-13
在配置文件app.config中加入
<appSettings>
<add key="LotDBConnection" value="DATA SOURCE=数据库连接;PASSWORD=密码;PERSIST SECURITY INFO=True;USER ID=登录名"/>
</appSettings>

//m_SqlPath 存放SQL语句的XML文件
Dim sqlHelper As New SQLHelper("LotDBConnection")
Dim sqlRead As New ResourceHelper
Dim ht As New Hashtable
Dim strSQL As String
Try
'设置SQL文参数
ht.Clear()
ht.Add(ColumnName.USER_ID.ToString, Trim(Me.txtUserID.Text))
ht.Add(ColumnName.USER_NAME.ToString, Trim(Me.txtUserName.Text))

'数据查询
strSQL = sqlRead.GetSQLSentence("GetUserList", m_SqlPath, ht)
ds = sqlHelper.ExecuteDataSet(strSQL)

If ds.Tables(0).Rows.Count = 0 Then
MessageBox .Show ("数据不存在");
Else
'数据绑定
dgvUserMeisai.DataSource = ds.Tables(0)

End If

Catch ex As Exception
MessageBox .Show (ex.Message );
Finally
sqlHelper = Nothing
sqlRead = Nothing
ht = Nothing
End Try
相似回答