Home > Net >  ADO.NET: not contained in this SqlParameterCollection with ParameterName "@ userage SqlParamete
ADO.NET: not contained in this SqlParameterCollection with ParameterName "@ userage SqlParamete

Time:10-23

Cunchuguocheng. Aspx:
<% @ Page Language="c #" AutoEventWireup="true" CodeFile="cunchuguocheng. Aspx. Cs" Inherits="cunchuguocheng % & gt;"



<meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "/& gt;


<body>

ID: & lt; Asp: TextBox ID="txt_userid" runat="server" & gt;

Name: & lt; Asp: TextBox ID="txt_username" runat="server" & gt;

Age: & lt; Asp: TextBox ID="txt_userage" runat="server" & gt;










Cs: cunchuguocheng. Aspx.
Using System;
using System.Collections.Generic;
Using System. The Data;
Using System. The Data. SqlClient.
Using System. Linq;
Using System. The Web;
Using System. Web. UI.
Using System. Web. UI. WebControls;

Public partial class cunchuguocheng: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{

}

Protected void Button1_Click (object sender, EventArgs e)
{
SqlConnection con=new SqlConnection (" Data Source=(local); Initial Catalog=user; Integrated Security=True ");
SqlCommand com=new SqlCommand (" insertuser ", con);
Com.Com mandType=CommandType. StoredProcedure;
//go to empty parameter array, then item by item to store in the process of variable assignment
Com. The Parameters. The Clear ();
Com. The Parameters. The Add (new SqlParameter (" @ "userid, SqlDbType. Char, 5));
Com. The Parameters [r]. "@ userid" Value=https://bbs.csdn.net/topics/txt_userid.Text;
Com. The Parameters. The Add (new SqlParameter (" @ the username ", SqlDbType. Char, 50));
Com. The Parameters [r]. "@ the username" Value=https://bbs.csdn.net/topics/txt_username.Text;
Com. The Parameters. The Add (new SqlParameter (" @ "userid, SqlDbType. Int, 20));
Com. The Parameters [r]. "@ userage" Value=https://bbs.csdn.net/topics/int.Parse (txt_userage. Text);
If (con) State==ConnectionState) Closed)
{
Con. The Open ();
}
Int records.=the Convert ToInt32 (com ExecuteNonQuery ());
If (records & gt; 0)
{
Label1. Text="add success";
}
The else
{
Label1. Text="add failure";
}
Com. The Dispose ();
If (con) State==ConnectionState) Open)
{
Con. The Close ();

}
}
}
Don't run the following two statements are correct: suggest that age is a problem here, all the procedures were related to age to delete, can correct operation,
//com. The Parameters. The Add (new SqlParameter (" @ "userid, SqlDbType. Int, 20));
//com. The Parameters [r]. "@ userage" Value=https://bbs.csdn.net/topics/int.Parse (txt_userage. Text);


The stored procedure in the SQL Server:
Error:
CREATE PROCEDURE insertuser
@ userid char (5),
@ the username char (50),
@ userage int
AS
The BEGIN
Insert into users (userid, username, userage) values (@ userid, @ username, @ userage)
END
GO
Delete userage right:
CREATE PROCEDURE insertuser
@ userid char (5),
@ the username char (50)
AS
The BEGIN
Insert into users (userid, username) values (@ userid, @ username)
END
GO

CodePudding user response:

Com. The Parameters. The Add (new SqlParameter (" @ userid ", SqlDbType. Int, 20));
Com. The Parameters [" @ userage "]. Value=https://bbs.csdn.net/topics/int.Parse (txt_userage. Text);

Userid or userage

CodePudding user response:

Less to write a line:

Com. The Parameters. The Add (new SqlParameter (" @ userage ", SqlDbType. Int));

CodePudding user response:

reference 1st floor is nu month god reply:
com. The Parameters. The Add (new SqlParameter (" @ userid ", SqlDbType. Int, 20));
Com. The Parameters [" @ userage "]. Value=https://bbs.csdn.net/topics/int.Parse (txt_userage. Text);

Userid or userage
should be userage I give it a try thanks

CodePudding user response:

Lack of parameter bai
  • Related