Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

cmd.ExecuteNonQuery() Error - Cannot find the problem? help

$
0
0

Hi,

New here, and I am currently having some serious difficulty with a project i am doing with ASP.net

Essentially I have made a page which has several text boxes where users can input data.

Once they click add vehicle data, it will lead them to the 'confirmation.aspx' page.

Code is as follows:

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="addcar.aspx.vb" Inherits="WebApplication1.addcar" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
<p>
<br />
CarName<asp:TextBox ID="tb_CarName" runat="server"></asp:TextBox>
</p>
<p>
<br />
Year<asp:TextBox ID="tb_Year" runat="server"></asp:TextBox>
</p>
<p>
<br />
EngineSize<asp:TextBox ID="tb_EngineSize" runat="server"></asp:TextBox>
</p>
<p>
<br />
BHP<asp:TextBox ID="tb_BHP" runat="server"></asp:TextBox>
</p>
<p>
<br />
Origin<asp:TextBox ID="tb_Origin" runat="server"></asp:TextBox>
</p>
<p>
<br />
Description<asp:TextBox ID="tb_Description" runat="server"></asp:TextBox>
</p>
<p>
<br />
Pictures<asp:TextBox ID="tb_Pictures" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Add Car Details" />
</p>
</asp:Content>

Code for the button:

Imports System.Data.OleDb

Public Class addcar
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("CarsConnectionString").ConnectionString)
Dim SqlString As String = "Insert into Table1(CarName,Year,EngineSize,BHP,Origin,Description,Pictures) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("@f1", tb_CarName.Text)
cmd.Parameters.AddWithValue("@f2", tb_Year.Text)
cmd.Parameters.AddWithValue("@f3", tb_EngineSize.Text)
cmd.Parameters.AddWithValue("@f4", tb_BHP.Text)
cmd.Parameters.AddWithValue("@f5", tb_Origin.Text)
cmd.Parameters.AddWithValue("@f6", tb_Description.Text)
cmd.Parameters.AddWithValue("@f7", tb_Pictures.Text)
oleDbConn.Open()
cmd.ExecuteNonQuery()
Response.Redirect("confirmation.aspx")


End Sub

End Class

Error I am recieving:

Line 20:         cmd.Parameters.AddWithValue("@f7", tb_Pictures.Text)
Line 21:         oleDbConn.Open()Line 22: cmd.ExecuteNonQuery() Line 23:         Response.Redirect("confirmation.aspx")
Line 24: 

Stack Trace: 

[OleDbException (0x80040e14): Syntax error in INSERT INTO statement.]
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) +1090740
   System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +247
   System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +189
   System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +58
   System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +162
   System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +107
   WebApplication1.addcar.Button1_Click(Object sender, EventArgs e) in C:\Users\MUBEEN\Desktop\PROJECT 2\WebApplication1\WebApplication1\addcar.aspx.vb:22
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9553594
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

Help Please :(


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>