Quantcast
Channel: DataSource Controls - SqlDataSource, ObjectDataSource, etc.
Viewing all articles
Browse latest Browse all 956

Must declare the scalar variable "@UserName".

$
0
0

Hi

I want to create a table that different user can insert their values. I intend every user can see his/her values then I write this:

<div><asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:universityConnectionString %>"
                SelectCommand="SELECT [UserName], [Date], [CalIntake], [CalBurn], [FatMass], [Show], [Delet], [Weight] FROM [UserCalorie]
                WHERE   (UserName = @UserName)"
                InsertCommand="INSERT INTO UserCalorie(Date, CalIntake, CalBurn, FatMass, Weight, UserName, Show)
                VALUES (@Date, @CalIntake, @CalBurn, @FatMass, @Weight, @UserName, @Show)"></asp:SqlDataSource><h1>User Calori Burn / Intake</h1><asp:FormView ID="FormView1" runat="server"
        DataSourceID="SqlDataSource1" DefaultMode="Insert"><InsertItemTemplate>
        calorie Intake:<asp:TextBox ID="txtCalIn" runat="server" Text = '<%# Bind( "CalIntake" ) %>'></asp:TextBox><br />
        calorie Burn:<asp:TextBox ID="TextBox1" runat="server" Text = '<%# Bind( "CalBurn" ) %>'></asp:TextBox><br />
        Fat Mass:<asp:TextBox ID="TextBox2" runat="server" Text = '<%# Bind( "FatMass" ) %>'></asp:TextBox><br />
        Weight:<asp:TextBox ID="TextBox3" runat="server" Text = '<%# Bind( "Weight" ) %>'></asp:TextBox><br />
        Date:<asp:TextBox ID="TextBox3" runat="server" Text = '<%# Bind( "Date" ) %>'></asp:TextBox><br /><asp:Button ID="btnSubmit" runat="server" CommandName="Insert" Text="submit" Font-Names="tahoma"
        OnClick="Button1_Click" /></InsertItemTemplate></asp:FormView></div>

and code behind is:

protected void Button1_Click(object sender, EventArgs e)
        {
            string userName1 = User.Identity.Name;
            SqlDataSource1.InsertParameters.Add("UserName", userName1);
            SqlDataSource1.InsertParameters.Add("Show", userName1);

        }

When I want to insert data the following error occur:

Must declare the scalar variable "@UserName".

Please help me!

regards,


Viewing all articles
Browse latest Browse all 956

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>