By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,852 Members | 1,014 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,852 IT Pros & Developers. It's quick & easy.

Problem in inserting data in sql server 2005 using asp.net

P: 2
Hi this is nidhi from india,

Since last 2 days i am facing a problem in asp.net code. The data base connection is done correctly as i can select the data from the database. But i can not insert the data to sql server 2005 .

A error message occurs saying "@vfirstname" is not declared. I donot understand where do i declare the parameter and how? How do i insert data using stored procedure? Please guide me as early as possible.

Do write the code that makes easy to understand. please

----------------------------------------------------------------------------------------------------------------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="login.aspx.vb" Inherits="_Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<Script runat="server">
Private Sub Insertmember(ByVal Source As Object, ByVal e As EventArgs)
SqlDataSource1.Insert()
End Sub
</Script>



<body>
<form id="form1" runat="server">

<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
InsertCommand = "Insert into memberlogin (cfirstname,clastname) values (@vcfistname,@vclastname)" >
<InsertParameters>
<asp:FormParameter Name="@vcfirstname" FormField="fname" />
<asp:FormParameter Name="@vclastname" FormField="lname" />
</InsertParameters>
</asp:SqlDataSource>


<table border="0" width="742" cellspacing="0" cellpadding="0" id="table1">
<tr>
<td style="width:50%">First Name:</td>
<td style="width:50%">

<asp:TextBox ID="fname" runat="server" > </asp:TextBox>
<asp:RequiredFieldValidator
id="RequiredFieldValidator1"
runat="server"
ControlToValidate="fname"
Display="Static"
ErrorMessage="Please enter a First Name." /> </td>

</tr>

</tr>
<tr>
<td style="width:50%">Last Name:</td>
<td style="width:50%">
<asp:TextBox ID="lname" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
id="RequiredFieldValidator2"
runat="server"
ControlToValidate="lname"
Display="Static"
ErrorMessage="Please enter a Last Name." />
</td>
</tr>

<tr>
<td colspan=2>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Insertmember"/> </td>
</tr>

</table>
</body>
</html>

--------------------------------------------------------------------------------------------------------------
Feb 16 '07 #1
Share this Question
Share on Google+
4 Replies


kenobewan
Expert 2.5K+
P: 4,871
Spelling would be the first thing that I would check. You have spelt the variable three different ways in your post...
Feb 16 '07 #2

P: 2
oh sorry, spelling is posted wrong in this thread but its not wrong in my script. Right now ignore the spell its @vcfirstname variable name. still the error is same variable is not declared. how do i declare variable as a sqlparameter? and how do i insert data using stored procedure?

Please guide
Feb 17 '07 #3

P: 17
Hi Nidhi,

U may use the following stored procedure:

CREATE PROCEDURE Login
(
@firstname varchar(50),
@lastname varchar(50)
)
AS

BEGIN
insert into T_Users(firstname,lastname )
values (@firstname,@lastname)
END
GO


In this case T_users is the table name.

Hope this will work fine for u.

Vivek.
Feb 21 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.