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
查看全文
相关阅读:
vue组件系列-数字滚动组件
重新振兴自己
EL表达式
org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type sette
Struts2常用标签总结
mybatis+strut2+spring整合总结
hibernate的详细注解以及例子
Struts2基于注解的Action配置
【干货】如何通过OPC自定义接口来实现客户端数据的读取?
即将离职,共享下我的知识库
原文地址:https://www.cnblogs.com/fuyingke/p/194583.html
最新文章
parseInt toString 接收参数
canvas 非零环绕原则
作业一·
实验三
10.24实验四
中国人民公安大学信息技术与网络安全学院 《网络攻击与防御》
网络侦查与网络扫描
javaScript排序,别再说你只会冒泡!!!
用原生js实现ajax。
用js创建10个<a>标签,点击时候弹出的对应序号。
热门文章
webpack学习笔记,前方有坑,请注意!!!!!
如何将本地项目通过git推送到github上!!!
作用域链
首屏,白屏时间如何计算??
前端的性能优化都有哪些方法??
js中__proto__和prototype的区别和关系?
MySQL数据库开启、关闭、查看函数功能的方法
update忘了加where条件,不小心把oracle数据库里某张表的全表数据都更新了怎么办?
input标签设置背景颜色
vue 动态菜单以及动态路由加载、刷新采的坑
Copyright © 2011-2022 走看看