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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • itsnidhu
    New Member
    • Feb 2007
    • 2

    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 "@vfirstnam e" 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="_Defa ult" %>


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

    <html>

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



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

    <asp:SqlDataSou rce
    ID="SqlDataSour ce1"
    runat="server"
    ConnectionStrin g="<%$ ConnectionStrin gs:ConnectionSt ring %>" ProviderName="< %$ ConnectionStrin gs:ConnectionSt ring.ProviderNa me %>"
    InsertCommand = "Insert into memberlogin (cfirstname,cla stname) values (@vcfistname,@v clastname)" >
    <InsertParamete rs>
    <asp:FormParame ter Name="@vcfirstn ame" FormField="fnam e" />
    <asp:FormParame ter Name="@vclastna me" FormField="lnam e" />
    </InsertParameter s>
    </asp:SqlDataSour ce>


    <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:RequiredFi eldValidator
    id="RequiredFie ldValidator1"
    runat="server"
    ControlToValida te="fname"
    Display="Static "
    ErrorMessage="P lease 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:RequiredFi eldValidator
    id="RequiredFie ldValidator2"
    runat="server"
    ControlToValida te="lname"
    Display="Static "
    ErrorMessage="P lease enter a Last Name." />
    </td>
    </tr>

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

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

    --------------------------------------------------------------------------------------------------------------
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Spelling would be the first thing that I would check. You have spelt the variable three different ways in your post...

    Comment

    • itsnidhu
      New Member
      • Feb 2007
      • 2

      #3
      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

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        Here is an article that may help:
        ASP.NET Jumpstart: Building the Data Tier of the Media Share Library Starter Kit
        and this thread:
        inserting data into sql form writes only null values

        Comment

        • Rathorevivek
          New Member
          • Dec 2006
          • 17

          #5
          Hi Nidhi,

          U may use the following stored procedure:

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

          BEGIN
          insert into T_Users(firstna me,lastname )
          values (@firstname,@la stname)
          END
          GO


          In this case T_users is the table name.

          Hope this will work fine for u.

          Vivek.

          Comment

          Working...