what is wrong (INSERT & UPDATE)

Syntax error in INSERT AND UPDATE

Page 1 of 1

2 Replies - 3424 Views - Last Post: 17 December 2005 - 05:44 AM

#1 folen   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 07-March 02

what is wrong (INSERT & UPDATE)

Posted 15 December 2005 - 09:20 AM

am doing some asp.net proj is c# and i need to add and update but it keep saying:

Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

Source Error:

Line 228: string tracksql = @"INSERT INTO news (title, short, body) VALUES ( '"+ TextBox1.Text + "' , '"+ TextBox2.Text + "' , '" + TextBox3.Text +"' )" ;
Line 229: cmdget1 = new OleDbCommand(tracksql ,cn);
Line 230: cmdget1.ExecuteNonQuery();
Line 231:
Line 232: cn.Close();

Source File: c:\inetpub\wwwroot\webapplication11\editanews.aspx.cs Line: 230

Stack Trace:

[OleDbException (0x80040e14): Syntax error in INSERT INTO statement.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(Commandbehavior behavior, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(Commandbehavior behavior, String method)
WebApplication11.editanews.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication11\editanews.aspx.cs:230
System.Web.UI.WebControls.Button.onclick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain() +1277

so my statmint must br wrong

but i added a breakpoint and this is what in the tracksql:

"INSERT INTO news (title, short, body) VALUES ( 'SAA1' , 'SAA2' , 'SAA3' )"

to me it lookes rigth

what am doing wrong?

pleaz help me

ps added the aspx.cs file nad puting here the aspx file:

<%@ Page language="c#" Codebehind="editanews.aspx.cs" AutoEventWireup="false" Inherits="WebApplication11.editanews" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="Javascript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:datagrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 432px" runat="server" Width="992px" Height="423px" DataSource="<%# dataSet201 %>" AutoGenerateColumns="False" SelectedIndex="1">
<ItemStyle HorizontalAlign="Right" Width="50px"></ItemStyle>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<asp:BoundColumn DataField="body" SortExpression="body" HeaderText="גוף"></asp:BoundColumn>
<asp:BoundColumn DataField="short" SortExpression="short" HeaderText="קצר"></asp:BoundColumn>
<asp:BoundColumn DataField="title" SortExpression="title" HeaderText="גוף"></asp:BoundColumn>
<asp:BoundColumn DataField="num" SortExpression="num" HeaderText="מס"></asp:BoundColumn>
</asp:datagrid><asp:button id="Button1" AutoPostBack="true" style="Z-INDEX: 102; LEFT: 704px; POSITION: absolute; TOP: 16px"
runat="server" Text="הוסף" CausesValidation="False"></asp:button><asp:dropdownlist id="DropDownList1" style="Z-INDEX: 103; LEFT: 568px; POSITION: absolute; TOP: 16px"
runat="server" AutoPostBack="True">
<asp:ListItem Value="הוסף" Selected="True">הוסף</asp:ListItem>
<asp:ListItem Value="הוצא">הוצא</asp:ListItem>
<asp:ListItem Value="עדכן">עדכן</asp:ListItem>
</asp:dropdownlist><asp:label id="Label1" style="Z-INDEX: 104; LEFT: 712px; POSITION: absolute; TOP: 88px" runat="server"> כותרת</asp:label><asp:textbox id="TextBox1" style="Z-INDEX: 105; LEFT: 400px; POSITION: absolute; TOP: 80px" runat="server"
Width="292px"></asp:textbox><asp:label id="Label2" style="Z-INDEX: 106; LEFT: 712px; POSITION: absolute; TOP: 144px" runat="server">קצר</asp:label><asp:textbox id="TextBox2" style="Z-INDEX: 107; LEFT: 392px; POSITION: absolute; TOP: 144px"
runat="server" Width="292px" Height="64px"></asp:textbox><asp:label id="Label3" style="Z-INDEX: 108; LEFT: 720px; POSITION: absolute; TOP: 216px" runat="server">גוף</asp:label><asp:textbox id="TextBox3" style="Z-INDEX: 109; LEFT: 24px; POSITION: absolute; TOP: 216px" runat="server"
Width="668px" Height="200px"></asp:textbox><asp:label id="Label4" style="Z-INDEX: 110; LEFT: 704px; POSITION: absolute; TOP: 48px" runat="server"
Visible="False">'מס</asp:label><asp:textbox AutoPostBack="True" id="TextBox4" style="Z-INDEX: 111; LEFT: 656px; POSITION: absolute; TOP: 48px"
runat="server" Width="24px" Visible="False"></asp:textbox>
<asp:Label id="Label5" style="Z-INDEX: 112; LEFT: 72px; POSITION: absolute; TOP: 40px" runat="server"
Visible="False" ForeColor="Red">חייב למלא את כולם</asp:Label></form>

PLEAZ HELP ME (i don't want to get fired :crazy: )

Attached File(s)

Is This A Good Question/Topic? 0
  • +

Replies To: what is wrong (INSERT & UPDATE)

#2 Munchen   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 06-February 05

Re: what is wrong (INSERT & UPDATE)

Posted 16 December 2005 - 08:48 PM

It's not because You have some identify column in Your table ? Or maybe another column ?

Btw, have You tried to run the query agains the database outside this script ?

And last, what database are You using ?

This post has been edited by Munchen: 16 December 2005 - 08:49 PM

Was This Post Helpful? 0
  • +
  • -

#3 Wizzy   User is offline

  • D.I.C Regular
  • member icon

Reputation: 6
  • View blog
  • Posts: 408
  • Joined: 20-November 05

Re: what is wrong (INSERT & UPDATE)

Posted 17 December 2005 - 05:44 AM

try this instead of your old insert command:

"INSERT INTO `news` (`title`, `short`, `body`) VALUES ( 'SAA1' , 'SAA2' , 'SAA3' )";

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1