回复 2# 小乌龟 的帖子
源码:
Imports System.Data
Imports System.Data.SqlClient
Public Class Insert
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.connstu = New System.Data.SqlClient.SqlConnection
Me.cmdstu = New System.Data.SqlClient.SqlCommand
Me.cmdstu1 = New System.Data.SqlClient.SqlCommand
'
'connstu
'
Me.connstu.ConnectionString = "workstation id=jf609;packet size=4096;integrated security=SSPI;data source=""."";pe" & _
"rsist security info=False;initial catalog=StudentsMS"
'
'cmdstu
'
Me. = "SELECT studentno FROM Rota WHERE (studentno = ?)"
Me.cmdstu.Connection = Me.connstu
Me.cmdstu.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Param1", System.Data.SqlDbType.VarChar, 8, "studentno"))
'
'cmdstu1
'
Me. = "INSERT INTO Rota (studentno, name, sex, birthdate, specialty) VALUES (?, ?, ?, ?," & _
" ?)"
Me.cmdstu1.Connection = Me.connstu
Me.cmdstu1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Param1", System.Data.SqlDbType.VarChar, 8, "studentno"))
Me.cmdstu1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.VarChar, 6, "name"))
Me.cmdstu1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Param3", System.Data.SqlDbType.VarChar, 2, "rthdate"))
Me.cmdstu1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Param5", System.Data.SqlDbType.VarChar, 50, "specialtysex"))
Me.cmdstu1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Param4", System.Data.SqlDbType.DateTime, 8, "bi"))
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents RFV1 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents RadioButtonList1 As System.Web.UI.WebControls.RadioButtonList
Protected WithEvents Label5 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox3 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label6 As System.Web.UI.WebControls.Label
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents CompareValidator1 As System.Web.UI.
Protected WithEvents Label7 As System.Web.UI.WebControls.Label
Protected WithEvents connstu As System.Data.SqlClient.SqlConnection
Protected WithEvents cmdstu As System.Data.SqlClient.SqlCommand
Protected WithEvents cmdstu1 As System.Data.SqlClient.SqlCommand
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
HyperLink1.NavigateUrl = "Index.aspx"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
connstu.Open()
cmdstu.Parameters("studentno").Value = TextBox1.Text
Dim rdstu As System.Data.SqlClient.SqlDataReader = cmdstu.ExecuteReader
If rdstu.Read Then
Label7.Text = "<script language=""vbscript"">alert""此学号已存在,请重新输入!""</script>"
rdstu.Close()
Else
rdstu.Close()
With cmdstu1
.Parameters("studentno").Value = TextBox1.Text
.Parameters("name").Value = TextBox2.Text
.Parameters("sex").Value = RadioButtonList1.SelectedValue
.Parameters("birthdate").Value = TextBox3.Text
.Parameters("speciality").Value = DropDownList1.SelectedValue
Dim n As Integer = .ExecuteNonQuery
If n > 0 Then
Label7.Text = "<script language=""vbscript"">alert""此记录已被成功保存!""</script>"
End If
End With
End If
End Sub
End Class
红色部分不是已经表示已经有了这个参数吗?????
[[it] 本帖最后由 hemingsheng 于 2008-6-17 17:12 编辑 [/it]]