Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old May 20th, 2005, 05:27 PM
Friend of Wrox
Join Date: Mar 2005
Location: , , .
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default errro trying to insert record to sql server

Hi experts. i got this asp.net that supposed to add records to matches table. but when i fill the text boxes
i get the following error.I be happy if some one help me fix this broken code.Thanks

ERROR: Could not add record, please ensure the fields are correctly filled out
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script language="VB" runat="server">

    Dim MyConnection As SqlConnection

    Sub Page_Load(Sender As Object, E As EventArgs) 

        MyConnection = New SqlConnection("server=(local);database=teniss2;User Id=web;Password=web;")

        If Not (IsPostBack)
        End If
    End Sub

    Sub Addmatches_Click(Sender As Object, E As EventArgs) 

        Dim DS As DataSet
        Dim MyCommand As SqlCommand

        If MATCHNO.Value = "" Or TEAMNO.Value = "" Or PLAYERNO.Value = "" Or WON.Value = ""

          Message.InnerHtml = "ERROR: Null values not allowed "
          Message.Style("color") = "red"
        End If

        Dim InsertCmd As String = "insert into matches (MATCHNO, TEAMNO, PLAYERNO ,WON, LOST) values (@LMATCHNO, @LTEAMNO, @LPLAYERNO, @LWON, @LLOST;)"

        MyCommand = New SqlCommand(InsertCmd, MyConnection)

        MyCommand.Parameters.Add(New SqlParameter("@LMATCHNO", SqlDbType.NVarChar, 11))
        MyCommand.Parameters("@LMATCHNO").Value = Server.HtmlEncode(MATCHNO.Value)

        MyCommand.Parameters.Add(New SqlParameter("@LTEAMNO", SqlDbType.NVarChar, 40))
        MyCommand.Parameters("@LTEAMNO").Value = Server.HtmlEncode(TEAMNO.Value)

        MyCommand.Parameters.Add(New SqlParameter("@LPLAYERNO", SqlDbType.NVarChar, 20))
        MyCommand.Parameters("@LPLAYERNO").Value = Server.HtmlEncode(PLAYERNO.Value)

        MyCommand.Parameters.Add(New SqlParameter("@LWON", SqlDbType.NChar, 12))
        MyCommand.Parameters("@LWON").Value = Server.HtmlEncode(WON.Value)

        MyCommand.Parameters.Add(New SqlParameter("@LLOST", SqlDbType.NVarChar, 40))
        MyCommand.Parameters("@LLOST").Value = Server.HtmlEncode(LOST.Value)



            Message.InnerHtml = "<b>Record Added</b><br>" & InsertCmd.ToString()

        Catch Exp As SQLException
            If Exp.Number = 2627
                Message.InnerHtml = "ERROR: A record already exists with the same primary key"
                Message.InnerHtml = "ERROR: Could not add record, please ensure the fields are correctly filled out"
            End If
            Message.Style("color") = "red"

        End Try


    End Sub

    Sub BindGrid() 

        Dim MyCommand As SqlDataAdapter = new SqlDataAdapter("select * from matches", MyConnection)

        Dim DS As DataSet = new DataSet()
        MyCommand.Fill(DS, "matches")

    End Sub


<body style="font: 10pt verdana">

  <form runat="server">

    <h3>Inserting A MATCHES RECORD</h3>

    <table width="95%">
        <td valign="top">

          <ASP:DataGrid id="MyDataGrid" runat="server"

        <td valign="top">

          <table style="font: 8pt verdana">
              <td colspan="2" bgcolor="#aaaadd" style="font:10pt verdana">Add a New record:</td>
              <td nowrap>MATCHNO: </td>
              <td><input type="text" id="MATCHNO" value="0000" runat="server"></td>
              <td nowrap>TEAMNO: </td>
              <td><input type="text" id="TEAMNO" value="0000" runat="server"></td>
            <tr nowrap>
              <td>Playerno: </td>
              <td><input type="text" id="PLAYERNO" value="0000" runat="server"></td>
              <td>Won: </td>
              <td><input type="text" id="WON" value="0000" runat="server"></td>
              <td>Lost: </td>
              <td><input type="text" id="LOST" value="0000" runat="server"></td>
              <td style="padding-top:15">
                <input type="submit" OnServerClick="Addmatches_Click" value="Add matches" runat="server">
              <td colspan="2" style="padding-top:15" align="center">
                <span id="Message" EnableViewState="false" style="font: arial 11pt;" runat="server"/>



  #2 (permalink)  
Old May 20th, 2005, 08:24 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,409
Thanks: 0
Thanked 16 Times in 16 Posts

Your sql query is incorrect. You have a ; some it shouldn't be:



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
insert multiple record in sql server annie_stwg ASP.NET 2.0 Basics 4 September 19th, 2006 08:56 AM
Insert Multiple Record in SQL Server in Once lauhong28 SQL Server 2000 1 February 24th, 2006 01:43 PM
How to unlock record in SQL Server database DDB001 SQL Server 2000 2 August 2nd, 2004 09:46 AM
Add new record in SQL Server database bhatnagar_shaily Classic ASP Components 3 September 24th, 2003 01:16 AM
Adding a new record to a sql server DB morpheus VB How-To 6 August 6th, 2003 06:15 PM

All times are GMT -4. The time now is 04:48 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.