Click here to Skip to main content
15,887,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
why this error shown The parameterized query '(@date datetime,@id nvarchar(4000),@course_Id nvarchar(1),@statu' expects the parameter '@id', which was not supplied.


What I have tried:

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="WebForm24.aspx.vb" Inherits="assigment.WebForm24" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div class="container">
        <div class="row">
            <div class="col-lg-12">
                <h2>subscribe for course</h2>
                </div>
            </div>
        </div>
    <asp:Label ID="Label1" runat="server" Text="select a course"></asp:Label>
    <asp:DropDownList ID="ddlcourse" runat="server"></asp:DropDownList>
    <asp:Button ID="subscribebtn" runat="server" Text="subscribe" OnClick="subscribebtn_Click" />
    <asp:Label ID="Lblmsg" runat="server" Text=""></asp:Label>

</asp:Content>


code behind
Imports System
Imports System.Web
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Imports System.Configuration
Imports System.Text
Imports System.IO
Imports System.Security.Cryptography
Imports System.Net.Mail


Public Class WebForm24
    Inherits System.Web.UI.Page
    Private ReadOnly _conString As String
    Public Sub New()
        _conString = WebConfigurationManager.ConnectionStrings("learningSystem").ConnectionString
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            Dim con As New SqlConnection(_conString)
            Dim cmd As New SqlCommand()
            cmd.CommandType = CommandType.Text
            cmd.CommandText = "Select * from tblcourse"
            cmd.Connection = con
            con.Open()
            ddlcourse.DataSource = cmd.ExecuteReader()
            ddlcourse.DataTextField = "course_name"
            ddlcourse.DataValueField = "course_Id"
            ddlcourse.DataBind()
            con.Close()

            Dim li As New ListItem("select a course", "-1")
            ddlcourse.Items.Insert(0, li)
        End If
    End Sub

    Protected Sub subscribebtn_Click(sender As Object, e As EventArgs)
        Dim con As New SqlConnection(_conString)
        Dim cmd As New SqlCommand()
        cmd.Connection = con
        cmd.CommandType = CommandType.Text
        con.Open()
        cmd.CommandText = "insert into tblsubscription (date,Id,course_Id,status)values(@date,@id,@course_Id,@status)"

        cmd.Parameters.AddWithValue("@date", DateTime.Now)
        cmd.Parameters.AddWithValue("@id", Session("S_uid"))
        cmd.Parameters.AddWithValue("@course_Id", ddlcourse.SelectedValue)
        cmd.Parameters.AddWithValue("@status", 0)
        cmd.ExecuteNonQuery()
        con.Close()
        Lblmsg.Text = "your subscription has been sent"
    End Sub


End Class
Posted
Updated 29-Aug-20 11:57am

1 solution

Because your Session value is returning NULL - "there is no value in the Session collection with the index "S_uid".

Now you need to use the debugger to find out why it isn't there ... and we can't do that for you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900