将原生的ADO 记录集绑定到MSGRID上

2023-10-20 06:50

本文主要是介绍将原生的ADO 记录集绑定到MSGRID上,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

None.gif Imports  System.Data
None.gif
Imports  System.Data.SqlClient
None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
Public   Class Form1 Class Form1
InBlock.gif    
Inherits System.Windows.Forms.Form
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
Windows 窗体设计器生成的代码#Region " Windows 窗体设计器生成的代码 "
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Public Sub New()Sub New()
InBlock.gif        
MyBase.New()
InBlock.gif
InBlock.gif        
'该调用是 Windows 窗体设计器所必需的。
InBlock.gif
        InitializeComponent()
InBlock.gif
InBlock.gif        
'在 InitializeComponent() 调用之后添加任何初始化
InBlock.gif

ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
InBlock.gif    
'窗体重写 dispose 以清理组件列表。
ExpandedSubBlockStart.gifContractedSubBlock.gif
    Protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)
InBlock.gif        
If disposing Then
InBlock.gif            
If Not (components Is NothingThen
InBlock.gif                components.Dispose()
InBlock.gif            
End If
InBlock.gif        
End If
InBlock.gif        
MyBase.Dispose(disposing)
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
InBlock.gif    
'Windows 窗体设计器所必需的
InBlock.gif
    Private components As System.ComponentModel.IContainer
InBlock.gif
InBlock.gif    
'注意: 以下过程是 Windows 窗体设计器所必需的
InBlock.gif
    '可以使用 Windows 窗体设计器修改此过程。
InBlock.gif
    '不要使用代码编辑器修改它。
InBlock.gif
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
InBlock.gif    
Friend WithEvents Button1 As System.Windows.Forms.Button
InBlock.gif    
Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
InBlock.gif    
Friend WithEvents Button2 As System.Windows.Forms.Button
ExpandedSubBlockStart.gifContractedSubBlock.gif    
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
InBlock.gif        
Me.DataGrid1 = New System.Windows.Forms.DataGrid
InBlock.gif        
Me.Button1 = New System.Windows.Forms.Button
InBlock.gif        
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
InBlock.gif        
Me.Button2 = New System.Windows.Forms.Button
InBlock.gif        
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
InBlock.gif        
Me.SuspendLayout()
InBlock.gif        
'
InBlock.gif
        'DataGrid1
InBlock.gif
        '
InBlock.gif
        Me.DataGrid1.DataMember = ""
InBlock.gif
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
InBlock.gif        
Me.DataGrid1.Location = New System.Drawing.Point(1648)
InBlock.gif        
Me.DataGrid1.Name = "DataGrid1"
InBlock.gif
        Me.DataGrid1.Size = New System.Drawing.Size(560280)
InBlock.gif        
Me.DataGrid1.TabIndex = 0
InBlock.gif        
'
InBlock.gif
        'Button1
InBlock.gif
        '
InBlock.gif
        Me.Button1.Location = New System.Drawing.Point(3688)
InBlock.gif        
Me.Button1.Name = "Button1"
InBlock.gif
        Me.Button1.Size = New System.Drawing.Size(20832)
InBlock.gif        
Me.Button1.TabIndex = 1
InBlock.gif        
Me.Button1.Text = "Fill Grid"
InBlock.gif
        '
InBlock.gif
        'SqlConnection1
InBlock.gif
        '
InBlock.gif
        Me.SqlConnection1.ConnectionString = "workstation id=HUOER;packet size=4096;user id=sa;data source=""LIZ-SERVER"";persist" & _
InBlock.gif        
" security info=False;initial catalog=wen"
InBlock.gif
        '
InBlock.gif
        'Button2
InBlock.gif
        '
InBlock.gif
        Me.Button2.Location = New System.Drawing.Point(1448)
InBlock.gif        
Me.Button2.Name = "Button2"
InBlock.gif
        Me.Button2.Size = New System.Drawing.Size(20032)
InBlock.gif        
Me.Button2.TabIndex = 2
InBlock.gif        
Me.Button2.Text = "使用原生ADO对象"
InBlock.gif
        '
InBlock.gif
        'Form1
InBlock.gif
        '
InBlock.gif
        Me.AutoScaleBaseSize = New System.Drawing.Size(614)
InBlock.gif        
Me.ClientSize = New System.Drawing.Size(584333)
InBlock.gif        
Me.Controls.Add(Me.Button2)
InBlock.gif        
Me.Controls.Add(Me.Button1)
InBlock.gif        
Me.Controls.Add(Me.DataGrid1)
InBlock.gif        
Me.Name = "Form1"
InBlock.gif
        Me.Text = "Form1"
InBlock.gif
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
InBlock.gif        
Me.ResumeLayout(False)
InBlock.gif
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockEnd.gif
#End Region

InBlock.gif
InBlock.gif    
Private sqlCOnn As String = "user id=sa;data source=LIZ-SERVER;persist security info=False;initial catalog=wen"
InBlock.gif
    Private NsqlCOnn As String = "Provider=SQLOLEDB.1;user id=sa;data source=LIZ-SERVER;persist security info=False;initial catalog=wen"
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif
    Public Function GetRs()Function GetRs(ByVal Sql As StringAs ADODB.Recordset
InBlock.gif        
Dim conn As New ADODB.Connection
InBlock.gif        
Dim comm As New ADODB.Command
InBlock.gif
InBlock.gif        conn.ConnectionString 
= NsqlCOnn
InBlock.gif        conn.Open()
InBlock.gif        comm.ActiveConnection 
= conn
InBlock.gif        comm.CommandText 
= Sql
InBlock.gif        
Return comm.Execute
InBlock.gif
ExpandedSubBlockEnd.gif    
End Function

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click
InBlock.gif
InBlock.gif        
Dim conn As New SqlClient.SqlConnection(sqlCOnn)
InBlock.gif        conn.Open()
InBlock.gif
InBlock.gif        
MsgBox(conn.State)
InBlock.gif
InBlock.gif        
Dim ad As New SqlCommand("select * from product", conn)
InBlock.gif
InBlock.gif        
Dim rs As New SqlClient.SqlDataAdapter(ad)
InBlock.gif
InBlock.gif        
Dim tab As New DataSet
InBlock.gif        rs.Fill(
tab"test")
InBlock.gif
InBlock.gif
InBlock.gif        
Me.DataGrid1.DataSource = tab
InBlock.gif
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Sub SqlConnection1_InfoMessage()Sub SqlConnection1_InfoMessage(ByVal sender As System.ObjectByVal e As System.Data.SqlClient.SqlInfoMessageEventArgs) Handles SqlConnection1.InfoMessage
InBlock.gif
ExpandedSubBlockEnd.gif    
End Sub

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
Private Sub Button2_Click()Sub Button2_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button2.Click
InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif        
Dim rs_YPDZT As New ADODB.Recordset
InBlock.gif        rs_YPDZT 
= GetRs("select * from book")
InBlock.gif     
InBlock.gif        
Dim ds_YPDZT As New Data.DataSet
InBlock.gif        
Dim da_YPDZT As New Data.OleDb.OleDbDataAdapter
InBlock.gif
InBlock.gif        da_YPDZT.Fill(ds_YPDZT, rs_YPDZT, 
"YPB")
InBlock.gif
InBlock.gif        
Me.DataGrid1.DataSource = ds_YPDZT
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif    
End Sub

ExpandedBlockEnd.gif
End Class

None.gif


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim conn As New SqlClient.SqlConnection(sqlCOnn)
        conn.Open()

        MsgBox(conn.State)

        Dim ad As New SqlCommand("select * from product", conn)

        Dim rs As New SqlClient.SqlDataAdapter(ad)

        Dim tab As New DataSet
        rs.Fill(tab, "test")


        Me.DataGrid1.DataSource = tab

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

   

     Dim rs_YPDZT As New ADODB.Recordset
        rs_YPDZT = GetRs("select * from book")
    
        Dim ds_YPDZT As New Data.DataSet
        Dim da_YPDZT As New Data.OleDb.OleDbDataAdapter

        da_YPDZT.Fill(ds_YPDZT, rs_YPDZT, "YPB")

        Me.DataGrid1.DataSource = ds_YPDZT


    End Sub
End Class

这篇关于将原生的ADO 记录集绑定到MSGRID上的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/245417

相关文章

前端原生js实现拖拽排课效果实例

《前端原生js实现拖拽排课效果实例》:本文主要介绍如何实现一个简单的课程表拖拽功能,通过HTML、CSS和JavaScript的配合,我们实现了课程项的拖拽、放置和显示功能,文中通过实例代码介绍的... 目录1. 效果展示2. 效果分析2.1 关键点2.2 实现方法3. 代码实现3.1 html部分3.2

VUE动态绑定class类的三种常用方式及适用场景详解

《VUE动态绑定class类的三种常用方式及适用场景详解》文章介绍了在实际开发中动态绑定class的三种常见情况及其解决方案,包括根据不同的返回值渲染不同的class样式、给模块添加基础样式以及根据设... 目录前言1.动态选择class样式(对象添加:情景一)2.动态添加一个class样式(字符串添加:情

React实现原生APP切换效果

《React实现原生APP切换效果》最近需要使用Hybrid的方式开发一个APP,交互和原生APP相似并且需要IM通信,本文给大家介绍了使用React实现原生APP切换效果,文中通过代码示例讲解的非常... 目录背景需求概览技术栈实现步骤根据 react-router-dom 文档配置好路由添加过渡动画使用

SpringMVC入参绑定特别注意

1.直接在controller中定义一个变量,但是此种传输方式有一个限制就是参数名和请求中的参数名必须保持一致,否则失效。 @RequestMapping("test2")@ResponseBodypublic DBHackResponse<UserInfoVo> test2(String id , String name){UserInfoVo userInfoVo = new UserInf

Maven(插件配置和生命周期的绑定)

1.这篇文章很好,介绍的maven插件的。 2.maven的source插件为例,可以把源代码打成包。 Goals Overview就可以查看该插件下面所有的目标。 这里我们要使用的是source:jar-no-fork。 3.查看source插件的example,然后配置到riil-collect.xml中。  <build>   <plugins>    <pl

react笔记 8-19 事件对象、获取dom元素、双向绑定

1、事件对象event 通过事件的event对象获取它的dom元素 run=(event)=>{event.target.style="background:yellowgreen" //event的父级为他本身event.target.getAttribute("aid") //这样便获取到了它的自定义属性aid}render() {return (<div><h2>{

react笔记 8-17 属性绑定 class绑定 引入图片 循环遍历

1、绑定属性 constructor(){super()this.state={name:"张三",title:'我是一个title'}}render() {return (<div><div>aaaaaaa{this.state.name}<div title={this.state.title}>我是一个title</div></div></div>)} 绑定属性直接使用花括号{}   注

react笔记 8-16 JSX语法 定义数据 数据绑定

1、jsx语法 和vue一样  只能有一个根标签 一行代码写法 return <div>hello world</div> 多行代码返回必须加括号 return (<div><div>hello world</div><div>aaaaaaa</div></div>) 2、定义数据 数据绑定 constructor(){super()this.state={na

微信小程序(一)数据流与数据绑定

一、单向数据流和双向数据流 1、单项数据流:指的是我们先把模板写好,然后把模板和数据(数据可能来自后台)整合到一起形成HTML代码,然后把这段HTML代码插入到文档流里面 优点:数据跟踪方便,流向单一,追寻问题比较方便【主要体现:微信小程序】。 缺点:就是写起来不太方便,如果修改UI界面数据需要维护对应的model对象 2、双向数据流:值和UI是双向绑定的,大家都知道,只要UI里面的值发生

使用http-request 属性替代action绑定上传URL

在 Element UI 的 <el-upload> 组件中,如果你需要为上传的 HTTP 请求添加自定义的请求头(例如,为了通过身份验证或满足服务器端的特定要求),你不能直接在 <el-upload> 组件的属性中设置这些请求头。但是,你可以通过 http-request 属性来自定义上传的行为,包括设置请求头。 http-request 属性允许你完全控制上传的行为,包括如何构建请求、发送请