标题:VB2005數據庫及SQL語法
只看楼主
jxyga111
Rank: 8Rank: 8
来 自:中華人民共和國
等 级:贵宾
威 望:33
帖 子:6015
专家分:895
注 册:2008-3-21
结帖率:70%
 问题点数:0 回复次数:4 
VB2005數據庫及SQL語法
我現在是自學VB2005但是發現,很多方式都與VB6.0不一樣,像連接數據庫,用SQL語法,都不一樣
望各位給幾個示例
謝謝
搜索更多相关主题的帖子: vb2005 
2008-10-17 11:16
winorange
Rank: 1
来 自:浙江宁波
等 级:新手上路
威 望:1
帖 子:136
专家分:0
注 册:2008-3-29
得分:0 
光连上我会了,可是我完全不会操作.

处处尽力尽快,一切顺其自然。
2008-10-17 11:21
ynyxsky
Rank: 2
等 级:新手上路
威 望:4
帖 子:132
专家分:8
注 册:2008-2-27
得分:0 
vb2005使用来操作数据库,操作方面要比vb6强大,sql语法上和vb6是一样的使用.
2008-10-17 14:14
ynyxsky
Rank: 2
等 级:新手上路
威 望:4
帖 子:132
专家分:8
注 册:2008-2-27
得分:0 
这是我一个程序里的模块,你试试吧

Imports System.Data
Imports System.Data.SqlClient


Module modSQLData
   Public ConnStr As String = "Persist Security Info=False;User ID=XXX;Password=XXX;Initial Catalog=XXX;Data Source=XXX;" '连接字符串
    Dim Conn As SqlConnection 'conn对象



#Region "填充返回dataset"

    Public Function FillDataSet(ByVal SQLStr As String) As DataSet
        Try
            Conn = New SqlConnection(ConnStr)
            Conn.Open()
            Dim da As SqlDataAdapter = New SqlDataAdapter(SQLStr, Conn)
            Dim ds As DataSet = New DataSet
            da.Fill(ds)
            Return ds
        Catch ex As Exception
            MsgBox(ex.Message.ToString, MsgBoxStyle.Information, "提示")
        Finally
            Conn.Close()
        End Try
    End Function

#End Region




#Region "执行SQL语句"
    Public Function EXESQLCommand(ByVal SqlStr As String) As Boolean
        Try
            Conn = New SqlConnection(ConnStr)
            Conn.Open()
            Dim SqlCmd As SqlCommand
            SqlCmd = New SqlCommand(SqlStr, Conn)
            SqlCmd.ExecuteNonQuery()
            Return True
        Catch ex As Exception
            MsgBox(ex.Message.ToString, MsgBoxStyle.Information, "提示")
        Finally
            Conn.Close()
        End Try
    End Function
#End Region



#Region "执行统计"
    Public Function EXESQLScalar(ByVal SqlStr As String) As Single
        Try
            Conn = New SqlConnection(ConnStr)
            Conn.Open()
            Dim SqlSc As SqlCommand
            Dim SqlCount As Single
            SqlSc = New SqlCommand(SqlStr, Conn)
            SqlCount = SqlSc.ExecuteScalar()
            EXESQLScalar = SqlCount
        Catch ex As Exception
            'MsgBox(ex.Message.ToString, MsgBoxStyle.Information, "提示")
            EXESQLScalar = 0
        Finally
            Conn.Close()
        End Try
    End Function
#End Region

如果要从数据库里取出数据显示在Datagridview上,那么如此使用:
dim SQLStr as string="select * from xxx"
DataGridView1.DataSource = FillDataSet(SQLStr).Tables(0)

如果要执行命令,如新增,删除,更新
dim SQLStr as string="inner........delete........update........"
EXESQLCommand(sqlstr)
2008-10-17 14:29
swjtu_li
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-10-17
得分:0 
你好
我也在学,老师让我做 库存系统;希望得到大家的帮助.我做的是餐饮系统中库存部分,包括订单管理,用户管理,出入库管理,耗损管理,统计查询等部分.
2008-10-17 17:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-238796-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.276208 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved