| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1282 人关注过本帖
标题:有没有人遇见过此类问题?
只看楼主 加入收藏
hemingsheng
Rank: 1
等 级:新手上路
帖 子:164
专家分:0
注 册:2007-5-16
结帖率:100%
收藏
 问题点数:0 回复次数:2 
有没有人遇见过此类问题?
此 SqlParameterCollection 中未包含带有 ParameterName“studentno”的 SqlParameter。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.IndexOutOfRangeException: 此 SqlParameterCollection 中未包含带有 ParameterName“studentno”的 SqlParameter。

有谁遇见过类似的问题吗?
怎么解决??
搜索更多相关主题的帖子: 此类 遇见 
2008-06-17 16:36
小乌龟
Rank: 2
等 级:新手上路
威 望:4
帖 子:1291
专家分:0
注 册:2007-9-28
收藏
得分:0 
说的很清楚了。 参数集里面缺少studentno这个东东
2008-06-17 16:45
hemingsheng
Rank: 1
等 级:新手上路
帖 子:164
专家分:0
注 册:2007-5-16
收藏
得分:0 
回复 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]]
2008-06-17 17:10
快速回复:有没有人遇见过此类问题?
数据加载中...
 
   



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

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