vb.net的DataGridView数据绑定
数据库查询语句里有COUNT、SUM、AVG、MAX、MIN这样的聚合函数,应该如何把这类的项绑定到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
<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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询