Click here to Skip to main content
15,891,473 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: FileUpload + string!! Pin
Farraj6-Apr-10 14:19
Farraj6-Apr-10 14:19 
GeneralRe: FileUpload + string!! Pin
Eddy Vluggen6-Apr-10 15:55
professionalEddy Vluggen6-Apr-10 15:55 
GeneralRe: FileUpload + string!! Pin
Farraj6-Apr-10 23:43
Farraj6-Apr-10 23:43 
GeneralRe: FileUpload + string!! Pin
Eddy Vluggen7-Apr-10 0:17
professionalEddy Vluggen7-Apr-10 0:17 
GeneralRe: FileUpload + string!! Pin
Farraj7-Apr-10 6:41
Farraj7-Apr-10 6:41 
GeneralRe: FileUpload + string!! Pin
Eddy Vluggen7-Apr-10 7:59
professionalEddy Vluggen7-Apr-10 7:59 
GeneralRe: FileUpload + string!! Pin
Farraj7-Apr-10 8:01
Farraj7-Apr-10 8:01 
QuestionSyntax error in UPDATE statement. ? Pin
Farraj2-Apr-10 3:43
Farraj2-Apr-10 3:43 
hello,

i have a Datalist and ACCESS DataBase, im using the update event in datalist to update two fields in my db.

first one is subj the second is text.

i get the Syntax error in update statement all the time while updating.

the primary key is my ID field in the db, and it was set to be the same in the datalist.

this is the C# code for the update method:

protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
 {
     Label lblsubj = (Label)e.Item.FindControl("lblsubj");
     string st = lblid.Text;
     TextBox txtBoxId = (TextBox)e.Item.FindControl("txtBoxId");
     TextBox txtBoxTitle = (TextBox)e.Item.FindControl("txtBoxTitle");
     TextBox txtBoxFile = (TextBox)e.Item.FindControl("txtBoxFile");
     TextBox txtBoxText = (TextBox)e.Item.FindControl("txtBoxText");
     string queryStr = "UPDATE news SET subj='" + txtBoxTitle.Text + "', ";
     queryStr += "text='" + txtBoxText.Text + "', ";
     queryStr += "WHERE id='" + st + "'";

      string connectionStr = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Server.MapPath("~/App_Data/db.mdb");
     OleDbConnection connectObj = new OleDbConnection(connectionStr);
     OleDbCommand cmd = new OleDbCommand(queryStr, connectObj);
     connectObj.Open();
     cmd.ExecuteNonQuery();
     connectObj.Close();
     this.DataList1.EditItemIndex = -1;
     BindTheDataList();
 }



And this is my ASPX page code:

<asp:DataList ID="DataList1" runat="server" DataKeyField="subj" Height="96px"
                     OnCancelCommand="DataList1_CancelCommand" OnDeleteCommand="DataList1_DeleteCommand"
                     OnEditCommand="DataList1_EditCommand" OnUpdateCommand="DataList1_UpdateCommand"
                     Style="position: static" Width="641px">
                     <EditItemStyle BackColor="DarkGray" ForeColor="Black" />
                     <EditItemTemplate>
                         <table id="TABLE1" language="javascript" onclick="return TABLE1_onclick()">
                             <tr>
                                 <td style="width: 90px">
                             Editing item:
                                     <asp:Label ID="lblid" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"id") %>'
                                         Visible="False"></asp:Label></td>
                             </tr>
                             <tr>
                                 <asp:Button ID="btnUPDATE" runat="server" BorderColor="Azure" CommandName="update"
                                     Text="update" /><asp:Button ID="Button4" runat="server" BorderColor="Azure" CommandName="delete"
                                         Text="delete" /><asp:Button ID="Button5" runat="server" BorderColor="Azure" CommandName="cancel"
                                             Text="cancel" /></tr>
                             <tr>
                             </tr>
                             <tr>
                                 <td style="width: 60px">
                                     Id</td>
                                 <td style="width: 520px">
                                     <asp:TextBox ID="txtBoxId" runat="server" Enabled="False" Width="18px" Text='<%# DataBinder.Eval(Container.DataItem,"id") %>'></asp:TextBox></td>
                             </tr>
                             <tr>
                                 <td style="width: 60px">
                                     Title</td>
                                 <td style="width: 520px">
                                     <asp:TextBox ID="txtBoxTitle" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"subj") %>'
                                         Width="319px"></asp:TextBox>
                                 </td>
                             </tr>
                             <tr>
                                 <td style="width: 60px; height: 133px;">
                                     Text</td>
                                 <td style="width: 520px; height: 133px;">
                                     <asp:TextBox ID="txtBoxText" runat="server" Height="184px" Text='<%#DataBinder.Eval(Container.DataItem,"text")%>'
                                         TextMode="MultiLine" Width="516px"></asp:TextBox>
                                 </td>
                             </tr>
                             <tr>
                                 <td style="width: 60px; height: 7px">
                                     File</td>
                                 <td style="width: 520px; height: 7px">
                                     <asp:TextBox ID="txtBoxFile" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"file") %>'
                                         Width="317px"></asp:TextBox></td>
                             </tr>

                         </table>
                     </EditItemTemplate>
                     <SelectedItemStyle Font-Size="Medium" />
                     <ItemTemplate>
                         <table style="width: 682px; height: 173px">
                             <tr>
                                 <asp:LinkButton ID="Linkbutton1" runat="server" CommandName="edit" Font-Bold="true"
                                     Font-Underline="false" ForeColor="gray" Text="Edit   "></asp:LinkButton></tr>
                          <tr>
                                 <td style="width: 9px;">
                                     <strong>Id</strong></td>
                                 <td style="width: 118px;">
                                     <%#DataBinder.Eval(Container.DataItem,"id")%>
                                 </td>
                             </tr>
                             <tr>
                                 <td style="width: 9px;">
                                     <strong>Title</strong></td>
                                 <td style="width: 118px;">
                                     <%#DataBinder.Eval(Container.DataItem,"subj")%>
                                 </td>
                             </tr>
                             <tr>
                                 <td style="width: 9px;">
                                     <strong>Text</strong></td>
                                 <td style="width: 118px;" id="TD1">
                                     <%#DataBinder.Eval(Container.DataItem,"text")%>
                                 </td>
                             </tr>
                            <tr>
                                 <td style="width: 9px;">
                                     <strong>File</strong></td>
                                 <td style="width: 118px;">
                                     <%#DataBinder.Eval(Container.DataItem,"file")%>
                                 </td>
                             </tr>
                         </table>
                     </ItemTemplate>
                 </asp:DataList>



the error i keep getting:



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

Source Error:


Line 77: OleDbCommand cmd = new OleDbCommand(queryStr, connectObj);
Line 78: connectObj.Open();
Line 79: cmd.ExecuteNonQuery();

Line 80: connectObj.Close();
Line 81: this.DataList1.EditItemIndex = -1;





this is the string that i get while debuging for the update statement :

"UPDATE news SET subj='aasda22', text='sdasd', WHERE id='4'"

all i need to know WHAT IS WRONG in my UPDATE statement !!

thanks for ur help.
AnswerRe: Syntax error in UPDATE statement. ? Pin
Muhammad Gouda2-Apr-10 4:42
Muhammad Gouda2-Apr-10 4:42 
GeneralRe: Syntax error in UPDATE statement. ? Pin
Farraj2-Apr-10 8:42
Farraj2-Apr-10 8:42 
AnswerRe: Syntax error in UPDATE statement. ? Pin
MyDevBank2-Apr-10 9:10
MyDevBank2-Apr-10 9:10 
GeneralRe: Syntax error in UPDATE statement. ? Pin
Farraj2-Apr-10 9:31
Farraj2-Apr-10 9:31 
GeneralRe: Syntax error in UPDATE statement. ? Pin
MyDevBank2-Apr-10 9:52
MyDevBank2-Apr-10 9:52 
GeneralRe: Syntax error in UPDATE statement. ? Pin
Farraj2-Apr-10 10:01
Farraj2-Apr-10 10:01 
GeneralRe: Syntax error in UPDATE statement. ? Pin
MyDevBank2-Apr-10 10:30
MyDevBank2-Apr-10 10:30 
AnswerRe: Syntax error in UPDATE statement. ? Pin
Eddy Vluggen2-Apr-10 10:21
professionalEddy Vluggen2-Apr-10 10:21 
GeneralRe: Syntax error in UPDATE statement. ? Pin
Farraj2-Apr-10 10:38
Farraj2-Apr-10 10:38 
GeneralRe: Syntax error in UPDATE statement. ? Pin
Eddy Vluggen2-Apr-10 10:50
professionalEddy Vluggen2-Apr-10 10:50 
GeneralRe: Syntax error in UPDATE statement. ? Pin
MyDevBank2-Apr-10 11:18
MyDevBank2-Apr-10 11:18 
GeneralRe: Syntax error in UPDATE statement. ? Pin
Muhammad Gouda2-Apr-10 12:50
Muhammad Gouda2-Apr-10 12:50 
GeneralRe: Syntax error in UPDATE statement. ? Pin
Eddy Vluggen2-Apr-10 13:59
professionalEddy Vluggen2-Apr-10 13:59 
Questionaspx with ajax, treeview postback to wrong page Pin
sigurdur einarsson2-Apr-10 3:32
sigurdur einarsson2-Apr-10 3:32 
AnswerRe: aspx with ajax, treeview postback to wrong page Pin
Muhammad Gouda2-Apr-10 4:47
Muhammad Gouda2-Apr-10 4:47 
GeneralRe: aspx with ajax, treeview postback to wrong page Pin
sigurdur einarsson2-Apr-10 4:59
sigurdur einarsson2-Apr-10 4:59 
GeneralRe: aspx with ajax, treeview postback to wrong page Pin
Muhammad Gouda2-Apr-10 12:56
Muhammad Gouda2-Apr-10 12:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.