zoukankan
html css js c++ java
.net與存存儲過程
Imports
System.Data
Imports
System.Data.SqlClient
Imports
System.Data.SqlTypes
Public
Class Form1
Class
Form1
Inherits
System.Windows.Forms.Form
Windows Form 設計工具產生的程式碼
#Region
" Windows Form 設計工具產生的程式碼 "
Public
Sub New()
Sub
New
()
MyBase
.
New
()
'
此為 Windows Form 設計工具所需的呼叫。
InitializeComponent()
'
在 InitializeComponent() 呼叫之後加入所有的初始設定
End Sub
'
Form 覆寫 Dispose 以清除元件清單。
Protected
Overloads
Overrides
Sub Dispose()
Sub
Dispose(
ByVal
disposing
As
Boolean
)
If
disposing
Then
If
Not
(components
Is
Nothing
)
Then
components.Dispose()
End
If
End
If
MyBase
.Dispose(disposing)
End Sub
'
為 Windows Form 設計工具的必要項
Private
components
As
System.ComponentModel.IContainer
'
注意: 以下為 Windows Form 設計工具所需的程序
'
您可以使用 Windows Form 設計工具進行修改。
'
請勿使用程式碼編輯器來修改這些程序。
Friend
WithEvents
Button1
As
System.Windows.Forms.Button
Friend
WithEvents
DataGrid1
As
System.Windows.Forms.DataGrid
Friend
WithEvents
SqlSelectCommand1
As
System.Data.SqlClient.SqlCommand
Friend
WithEvents
SqlInsertCommand1
As
System.Data.SqlClient.SqlCommand
Friend
WithEvents
SqlConnection1
As
System.Data.SqlClient.SqlConnection
Friend
WithEvents
SqlDataAdapter1
As
System.Data.SqlClient.SqlDataAdapter
Friend
WithEvents
Button2
As
System.Windows.Forms.Button
Friend
WithEvents
TextBox1
As
System.Windows.Forms.TextBox
<
System.Diagnostics.DebuggerStepThrough()
>
Private
Sub InitializeComponent()
Sub
InitializeComponent()
Me
.Button1
=
New
System.Windows.Forms.Button
Me
.DataGrid1
=
New
System.Windows.Forms.DataGrid
Me
.SqlSelectCommand1
=
New
System.Data.SqlClient.SqlCommand
Me
.SqlInsertCommand1
=
New
System.Data.SqlClient.SqlCommand
Me
.SqlConnection1
=
New
System.Data.SqlClient.SqlConnection
Me
.SqlDataAdapter1
=
New
System.Data.SqlClient.SqlDataAdapter
Me
.Button2
=
New
System.Windows.Forms.Button
Me
.TextBox1
=
New
System.Windows.Forms.TextBox
CType
(
Me
.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me
.SuspendLayout()
'
'
Button1
'
Me
.Button1.Location
=
New
System.Drawing.Point(
8
,
8
)
Me
.Button1.Name
=
"
Button1"
Me
.Button1.Size
=
New
System.Drawing.Size(
80
,
24
)
Me
.Button1.TabIndex
=
0
Me
.Button1.Text
=
"
Button1"
'
'
DataGrid1
'
Me
.DataGrid1.DataMember
=
"
"
Me
.DataGrid1.HeaderForeColor
=
System.Drawing.SystemColors.ControlText
Me
.DataGrid1.Location
=
New
System.Drawing.Point(
8
,
48
)
Me
.DataGrid1.Name
=
"
DataGrid1"
Me
.DataGrid1.Size
=
New
System.Drawing.Size(
440
,
176
)
Me
.DataGrid1.TabIndex
=
1
'
'
SqlSelectCommand1
'
Me
.SqlSelectCommand1.CommandText
=
"
SELECT studentID, studentName, studentAge, studentDesc FROM Student"
Me
.SqlSelectCommand1.Connection
=
Me
.SqlConnection1
'
'
SqlInsertCommand1
'
Me
.SqlInsertCommand1.CommandText
=
"
INSERT INTO Student(studentID, studentName, studentAge, studentDesc) VALUES (@stu
"
&
_
"
dentID, @studentName, @studentAge, @studentDesc); SELECT studentID, studentName,
"
&
_
"
studentAge, studentDesc FROM Student"
Me
.SqlInsertCommand1.Connection
=
Me
.SqlConnection1
Me
.SqlInsertCommand1.Parameters.Add(
New
System.Data.SqlClient.SqlParameter(
"
@studentID
"
, System.Data.SqlDbType.
Int
,
4
,
"
studentID
"
))
Me
.SqlInsertCommand1.Parameters.Add(
New
System.Data.SqlClient.SqlParameter(
"
@studentName
"
, System.Data.SqlDbType.VarChar,
10
,
"
studentName
"
))
Me
.SqlInsertCommand1.Parameters.Add(
New
System.Data.SqlClient.SqlParameter(
"
@studentAge
"
, System.Data.SqlDbType.
Int
,
4
,
"
studentAge
"
))
Me
.SqlInsertCommand1.Parameters.Add(
New
System.Data.SqlClient.SqlParameter(
"
@studentDesc
"
, System.Data.SqlDbType.VarChar,
50
,
"
studentDesc
"
))
'
'
SqlConnection1
'
Me
.SqlConnection1.ConnectionString
=
"
workstation id=FYK;packet size=4096;integrated security=SSPI;data source=FYK;pers
"
&
_
"
ist security info=True;initial catalog=test"
'
'
SqlDataAdapter1
'
Me
.SqlDataAdapter1.InsertCommand
=
Me
.SqlInsertCommand1
Me
.SqlDataAdapter1.SelectCommand
=
Me
.SqlSelectCommand1
Me
.SqlDataAdapter1.TableMappings.AddRange(
New
System.Data.Common.DataTableMapping() {
New
System.Data.Common.DataTableMapping(
"
Table
"
,
"
Student
"
,
New
System.Data.Common.DataColumnMapping() {
New
System.Data.Common.DataColumnMapping(
"
studentID
"
,
"
studentID
"
),
New
System.Data.Common.DataColumnMapping(
"
studentName
"
,
"
studentName
"
),
New
System.Data.Common.DataColumnMapping(
"
studentAge
"
,
"
studentAge
"
),
New
System.Data.Common.DataColumnMapping(
"
studentDesc
"
,
"
studentDesc
"
)})})
'
'
Button2
'
Me
.Button2.Location
=
New
System.Drawing.Point(
224
,
8
)
Me
.Button2.Name
=
"
Button2"
Me
.Button2.Size
=
New
System.Drawing.Size(
72
,
24
)
Me
.Button2.TabIndex
=
2
Me
.Button2.Text
=
"
返回值"
'
'
TextBox1
'
Me
.TextBox1.Location
=
New
System.Drawing.Point(
312
,
8
)
Me
.TextBox1.Name
=
"
TextBox1"
Me
.TextBox1.Size
=
New
System.Drawing.Size(
128
,
22
)
Me
.TextBox1.TabIndex
=
3
Me
.TextBox1.Text
=
"
"
'
'
Form1
'
Me
.AutoScaleBaseSize
=
New
System.Drawing.Size(
5
,
15
)
Me
.ClientSize
=
New
System.Drawing.Size(
456
,
229
)
Me
.Controls.Add(
Me
.TextBox1)
Me
.Controls.Add(
Me
.Button2)
Me
.Controls.Add(
Me
.DataGrid1)
Me
.Controls.Add(
Me
.Button1)
Me
.Name
=
"
Form1"
Me
.Text
=
"
Form1"
CType
(
Me
.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me
.ResumeLayout(
False
)
End Sub
#End Region
Private
Sub Button1_Click()
Sub
Button1_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button1.Click
'
返回記錄集
'
Dim cn As New SqlClient.SqlConnection("server=.;database=test;password=;user id=sa")
Dim
cn
As
New
SqlClient.SqlConnection
cn.ConnectionString
=
Me
.SqlConnection1.ConnectionString
cn.Open()
Dim
cm
As
New
SqlClient.SqlCommand(
"
sp_studentQuery
"
, cn)
Dim
ada
As
New
SqlClient.SqlDataAdapter
Dim
trm
As
SqlClient.SqlTransaction
cm.CommandType
=
CommandType.StoredProcedure
cm.Parameters.Add(
"
@studentID
"
, SqlDbType.BigInt).Value
=
1
'
Dim sqlParams() As SqlClient.SqlParameter = {New SqlParameter("@studentID", 10)}
'
cm.Parameters.Add(sqlParams(0))
MsgBox
(cm.Parameters.Count().ToString())
'
cm.ExecuteReader()
ada.SelectCommand
=
cm
Dim
dataset
As
New
Data.DataTable
ada.Fill(dataset)
Me
.DataGrid1.DataSource
=
dataset
'
cm.Transaction = trm
Try
MsgBox
(cm.Parameters.Count().ToString()
+
cm.ExecuteReader.FieldCount.ToString)
'
trm.Commit()
Catch
ex
As
Exception
'
trm.Rollback()
End
Try
'
MsgBox(cn.State.ToString)
End Sub
Private
Sub Button2_Click()
Sub
Button2_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
Button2.Click
'
返回值
Dim
cn
As
New
SqlClient.SqlConnection
cn.ConnectionString
=
Me
.SqlConnection1.ConnectionString
cn.Open()
Dim
cm
As
New
SqlClient.SqlCommand(
"
sp_add
"
, cn)
Dim
trm
As
SqlClient.SqlTransaction
Dim
ada
As
New
SqlClient.SqlDataAdapter
cm.CommandType
=
CommandType.StoredProcedure
cm.Parameters.Add(
"
@a
"
, SqlDbType.BigInt).Value
=
152
cm.Parameters.Add(
"
@b
"
, SqlDbType.BigInt).Value
=
11
cm.Parameters.Add(
"
@c
"
, SqlDbType.BigInt).Direction
=
ParameterDirection.Output
cm.ExecuteNonQuery()
Dim
s
As
Object
=
cm.Parameters(
"
@c
"
).Value
MsgBox
(
CType
(s,
String
))
End Sub
End Class
查看全文
相关阅读:
[Linux 004]——用户和用户组以及 Linux 权限管理(二)
[Linux 003]——用户和用户组以及 Linux 权限管理(一)
[Linux 002]——Linux的常用命令
[Linux 001]——计算机和操作系统的基础知识
给 Android 开发者的 RxJava 详解
Mac OSX系统搭建React natvie for android 开发环境
Java中的堆和栈的区别
Nginx配置详解
在博客园安家了!
J2SE核心实战开发—— 集合类框架
原文地址:https://www.cnblogs.com/fuyingke/p/194583.html
最新文章
java代码执行顺序
JVM原理及调优
搭建vue前端项目
实训总结
周记(一)
使用git错误日志
通过Servlet设置文件下载
任务08——第一次半月学习总结
任务三 简单程序测试及 GitHub Issues 的使用
任务02——安装 Intellj IDEA,编写一个简易四则运算小程序,并将代码提交到 GitHub
热门文章
任务01——谈谈对参与工作室的预期
过半总结
任务05—学习 MARKDOWN 语言
任务02——安装 Intellj IDEA,编写一个简易四则运算小程序,并将代码提交到 GitHub
任务01——谈谈对参与工作室的预期
任务8
任务02——安装 Intellj IDEA,编写一个简易四则运算小程序,并将代码提交到 GitHub
任务
[Linux 006]——grep和正则表达式
[Linux 005]——IO重定向
Copyright © 2011-2022 走看看