473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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

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
4 1472
kenobewan
4,871 Expert 4TB
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
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
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

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

Similar topics

6
by: yoshitha | last post by:
hi db : sql server 2000 lan : C#.net(ASp.Net) in my database table there are 2 fileds of data type datatime. in field 1 i'm storing date in field 2 i'm storing time.
5
by: hfk0 | last post by:
Hi, I'm new to ASP.net, SQL Server and visual studio.net, and I'm having problem inserting and storing data from a web form to a SQL database. I created a simple ASP.NET web form, a simple SQL...
3
by: laststubborn | last post by:
Dear Memebers, I have a critical problem. I have an application is running on 64 bit machine. It used to be running on 32 bit machine. That application is using a Stored Procedure that uses...
12
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.