Hi there, I'm having a problem where the data taken from the textboxes is being inserted into a table twice. I looked online and someone on another forum was experiencing the same problem. His solution was making the "submitdsabledcontrols" attribute of the form false. That hasn't fixed the issue for me. Below is my code. I'm still learning all this so this is just a test page, hence the wacky naming conventions. When the button click calls Button1_Click, all it runs is "SqlDataSource1.Insert()" Any ideas? <%@ Page EnableEventValidation="false" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" title="Untitled Page" %> <asp:Content ID="Content1" ContentPlaceHolderID="mainContent" Runat="Server"> <form id="form1" submitdisabledcontrols=false> <br /> <asp:Label ID="Label1" runat="server">Name</asp:Label> <asp:TextBox ID="NameTextBox" runat="server"></asp:TextBox> <br /> <br /> <asp:Label ID="Label2" runat="server" Text="Label">Number</asp:Label> <asp:TextBox ID="NumberTextBox" runat="server"></asp:TextBox> <br /> <br /> <asp:Label ID="Label3" runat="server" Text="Label">Salary</asp:Label> <asp:TextBox ID="SalaryTextBox" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_click" /> </form> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pubsConnectionString1 %>" DeleteCommand="DELETE FROM [Table1] WHERE [TableID] = @original_TableID" InsertCommand="INSERT INTO [Table1] ([Name], [Number], [Salary]) VALUES (@Name, @Number, @Salary)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Table1]" UpdateCommand="UPDATE [Table1] SET [Name] = @Name, [Number] = @Number, [Salary] = @Salary WHERE [TableID] = @original_TableID"> <DeleteParameters> <asp:Parameter Name="original_TableID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Name" Type="String" /> <asp:Parameter Name="Number" Type="String" /> <asp:Parameter Name="Salary" Type="Decimal" /> <asp:Parameter Name="original_TableID" Type="Int32" /> </UpdateParameters>
Server: Msg 170, Level 15, State 1, Line 17 Line 17: Incorrect syntax near ')'.
When I try to execute this code from SQL Query Analyzer...
DECLARE @DPPNumberCursor INT DECLARE DPPNumberCursor Cursor for Select PPAP_ID from ppap where ppap_cancel <> "1" and ppap_close <> "1" and projectonhold <> "1"
OPEN DPPNumberCursor
Fetch Next From DPPNumberCursor
INTO @dppnumbercursor
While @@Fetch_Status = 0 Begin INSERT INTO APQPSubformTable (apqpsub_id) Values (@dppnumbercursor)
Bsically, I want to insert the number held in @dppnumbercursor in the APQPSub_id field.
Ok, the following four lines are four lines of code that I'm running, I'll post the code and then explain my issue: sqlCommand = New SQLCommand("INSERT INTO Bulk (Bulk_Run, Bulk_Totes, Bulk_Drums, Bulk_Boxes, Bulk_Bags, Bulk_Bins, Bulk_Crates) VALUES (" & RunList(x,0) & ", " & Totes & ", " & Drums & ", " & Boxes & ", " & Bags & ", " & Bins & ", " & Crates & ")", Connection) sqlCommand.ExecuteNonQuery() sqlCommand = New SQLCommand("INSERT INTO Presort (Presort_Run, Presort_Totes, Presort_Drums, Presort_Boxes, Presort_Bags, Presort_Bins, Presort_Crates) VALUES (" & RunList(x,0) & ", " & Totes & ", " & Drums & ", " & Boxes & ", " & Bags & ", " & Bins & ", " & Crates & ")", Connection) sqlCommand.ExecuteNonQuery() The two tables (Bulk & Presort) are <b>exactly</b> the same. This includes columns, primary keys, IDs, and even permissions. If I run the last two liens (the INSERT INTO Presort) then it works fine without error. But whenever I run the first two lines (the INSERT INTO Bulk) I get the following error: Incorrect syntax near the keyword 'Bulk'. Anyone have any ideas, thanks
Here is my insert statement: StringBuilder sb = new StringBuilder(); sb.Append("INSERT INTO patients_import_test "); sb.Append("(Referral_Number,Referral_Date,FullName,Patient_ien,DOB,FMP,SSN_LastFour,Race_Id,PCM,Age) "); sb.Append("VALUES(@rnum,@rdate,@fname,@patid,@birthDate,@fmp,@ssan,@race,@pcm,@age) "); sb.Append("WHERE Referral_Number NOT IN ( SELECT Referral_Number FROM patients_import_test )");I'm getting an "Incorrect syntax near the keyword 'WHERE'".If I remove the WHERE clause the INSERT statement work fine.
Server Error in '/ys(Do Not Remove!!!)' Application.
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 8: <Script runat="server"> Line 9: Private Sub InsertAuthorized(ByVal Source As Object, ByVal e As EventArgs) Line 10: SqlDataSource1.Insert() Line 11: End Sub ' InsertAuthorized Line 12: </Script> Source File: C:Documents and SettingsDream_AchieverDesktopys(Do Not Remove!!!)Authorizing.aspx Line: 10
Public DBString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Q:VoicenetRTS FolderRTS ChargesAccountscosting.mdb" Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click Dim connstring As New OleDbConnection(DBString) connstring.Open() Dim searchstring As String = "SELECT * FROM Costings1" Dim da As New OleDbDataAdapter(searchstring, connstring) Dim DS As New DataSet() Dim dt As DataTable = DS.Tables("Costings1") da.FillSchema(DS, SchemaType.Source, "Costings1") da.Fill(DS, "Costings1") Dim cb As New OleDbCommandBuilder(da) da.InsertCommand = cb.GetInsertCommand da.UpdateCommand = cb.GetUpdateCommand Dim dr As DataRow = DS.Tables("Costings1").NewRow dr("Key") = TextBox1.Text dr("CODE") = TextBox2.Text dr("Element") = TextBox3.Text etc... DS.Tables("Costings1").Rows.Add(dr) da.Update(DS, "Costings1") <<<<<<<<<<<Syntax error in INSERT INTO statement.
Hi All I'm having a bit of trouble with an sql statement being inserted into a database - here is the statement: string sql1; sql1 = "INSERT into Customer (Title, FirstName, FamilyName, Number, Road, Town,"; sql1 += " Postcode, Phone, DateOfBirth, email, PaymentAcctNo)"; sql1 += " VALUES ("; sql1 += "'" + TxtTitle.Text + "'," ; sql1 += "'" + TxtForename.Text + "'," ; sql1 += "'" + TxtSurname.Text + "'," ; sql1 += "'" + TxtHouseNo.Text + "',"; sql1 += "'" + TxtRoad.Text + "',"; sql1 += "'" + TxtTown.Text + "',"; sql1 += "'" + TxtPostcode.Text + "',"; sql1 += "'" + TxtPhone.Text + "',"; sql1 += "'" + TxtDob.Text + "',"; sql1 += "'" + TxtEmail.Text + "',"; sql1 += "'" + TxtPayAcc.Text + "')"; Which generates a statement like:INSERT into Customer (Title, FirstName, FamilyName, Number, Road, Town, Postcode, Phone, DateOfBirth, email, PaymentAcctNo) VALUES ('Mr','Test','Test','129','Test Road','Plymouth','PL5 1LL','07855786111','14/04/1930','mr@test.com','123456') I cannot for the life of me figure out what is wrong with this statement. I've ensured all the fields within the database have no validation (this is done within my ASP code) that would stop this statement being inserted. Line 158: dbCommand.Connection = conn;Line 159: conn.Open();Line 160: dbCommand.ExecuteNonQuery();Is the line that brings up the error - I presume this could be either an error in the statement or maybe some settings on the Database stopping the values being added. Any ideas which of this might be ? I'm not looking for someone to solve this for me, just a push in the right direction! Thanks!
This works: SqlDataSource1.ConnectionString = "Data Source=mydb.myserver.com;Initial Catalog=mydbname;User ID=mydblogin; pwd=mydbpassword"; This doesn't: SqlDataSource1.ConnectionString = "<%$ ConnectionStrings:myConnectionString_from_WebConfig %>" Ok, how do I tell it to use my connection string from my web.config?
Hi, nice to meet you all. I need to return a parameter value from a store procedure, i already done insert(), update(), delete() to return parameter back. Just only select() can't return parameter and it need argument, I try to write in Sqldatasource1.Select(Argument.empty), it can't work and return null. How should i solve the problem? Or I wirte the wrong argument? Can anyone help me? Thank in advance.
I Have This StoredProcedure ALTER PROCEDURE dbo.Default_Edit1 ( @ID int, @Family Nvarchar (100) OutPut ) AS SELECT @Family=Family FROM Table1 where (ID=@ID) RETURN I went to use SqlDataSource1.SelectParameters to Return Data Ho to get and set @ID , @Family with SelectParameters ?
Hi to all, I'm writting code that needs to pass data returned by a SqlDataSource object to another object (user control to graph data) Query in SqlDataSource object is OK, I've seen data returned by it at a GridView Object but I need to pass that data to an user control that needs a reference to the table that has the data ... What would be the code that do that task ?? I'm new to develop web applications... using Visual Web Developer Express 2008 Help in advance
Hello. I have the below INSERT statement in an application, which works fine. However, I can't figure out how to insert data into a new column. The new column is text3, and the text would be TextBox4.Text + / + TextBox5.Text + / + TextBox6.Text + / TextBox7.Text. Where the "/" is text and not an operator. Every syntax I try doesn't work. Any ideas would be appreciated! INSERT INTO table (updateTime, text4, text5, text6, text7, updateTime1) VALUES (getdate(), '" + this.TextBox4.Text + "', '" + this.TextBox5.Text + "', '" + this.TextBox6.Text + "', '" + this.TextBox7.Text + "', CONVERT(VARCHAR(19), GETDATE(), 120) + Space(2) )
The element in italics is the problem I suspect. It is a text string to be entered into the table. It is actually a variable, I have taken this from a log as it shows the value instead.
I get this error... quote:(STMT SQL Info:SQLPrepare [ S1000] Code:-201, [DataDirect][ODBC SequeLink driver][ODBC Socket][DataDirect][ODBC FileMaker driver][FileMaker]Parse Error in SQL q:F) (0xffffffff)
I am assuming the problem lies in the inverted commas (") in the italic string, is this right? How can I get around this or will I have to code them out before they become a string value in the variable?
HelloCan anyone help me translate this from access so that it can work in mssql(i need to get next value, but cannot use identity as if row is deleted,another must get new next column number which would be same as deleted one)Access;INSERT INTO tableSELECT(IIF(code<>Null,MAX(code)+1,1) AS code,0 AS usercodeFROM tableI tried this in mssql but will not work:INSERT INTO tableSELECTCASEWHEN code IS NULL THEN 1ELSE MAX(code)+1ENDAS code,0 AS usercodeFROM table
I am writing a stored procedure: CREATE PROCEDURE rasp_FillDescrColumnNames @TableNameD varchar(50), @TableNameU varchar(50), @TableUID int -- -- AS ......
Insert into @TableNameD(ColumnName) Select #TempColumnNames.Name From #TempColumnNames
----------------------------- I get "incorrect syntax near '@TableName'". (The input table does have a column called 'ColumnName'). How do you parametized an 'Insert Into' sql statement? I have tried a number of ways to no avail. Thanks, Judith
I have a insert statement but one of the strings contains a apostrophe. If I leave the apostrophe in an error occurs becuase it thinks that it is the end of the string. What is the proper syntax for including apostrophes in a string?
I'm working in vb.net and want to use a stored procedure to insert all employees from one db into my db. I can insert one by one, but I would like to get them all in without looping.
How would I do this? I've tried bulk insert, but I keep getting syntax errors; I've read the books online, but don't quite understand what they mean. I don't want to use DTS, should I?
I have a DTS package which, apart from other steps, loads a text file to the SQL Server (2000) table. The problem is that I need to do it for at least 20 text files, may be more. As far as I have no experience in parametrizing DTS packages, I suppose it will be easier for me to do it with BULK INSERT.
What would be an equivalent BULK INSERT syntax for this load (parameters taken from the DTS package mentioned)?
--------------------------------------- load a text file: path/txtfile.txt (txtfile.txt on the network drive) to an SQL Server 2000 table: db1.dbo.table1
Select File Format: - Delimited - File type: ANSI - Row delimiter: Comma - Text qualifier: Double Quote - First row has column names: NO
CREATE PROCEDURE Add_Junk @Dist char, @CheckNo int =null OUTPUT AS Set NoCount On BEGIN TRANSACTION INSERT INTO Junk (Dist) VALUES (@Dist) COMMIT TRANSACTION select @CheckNo=@@IDENTITY
If what I pass is "416" I only get the "4" in my database and nothing else. I don't get an error message. What is wrong with my syntax?
The following code should insert into 3 tables based on conditions. There's something screwy in my syntax and I'm pretty new at this can anyone help with transforming this in terms of performance and being syntactically correct? Thanks a million!
IF Not Exists (SELECT [Artist] FROM [integration].[dbo].[tblMusic_Artist] WHERE [Artist] = @Artist) BEGIN INSERT INTO [integration].[dbo].[tblMusic_Artist] ( [Artist], [Genre], [NLink])
VALUES ( @Artist, @Genre, @NLink)
SET @NewArtistID = @@IDENTITY
INSERT INTO [integration].[dbo].[tblMusic_Albums] ( [Album]
VALUES ( @Album)
SET @NewAlbumID = @@IDENTITY
INSERT INTO [integration].[dbo].[tblMusic_Song] ( [Song], [ArtistID], [AlbumID], [SLink])
VALUES ( @Song, @NewArtistID, @NewAlbumID, @SLink) END
ELSE BEGIN IF Not Exists (SELECT [Album] FROM [integration].[dbo].[tblMusic_Album] WHERE [Album] = @Album) BEGIN INSERT INTO [integration].[dbo].[tblMusic_Albums] ( [Album]
VALUES ( @Album)
SET @NewAlbumID = @@IDENTITY SET @NewArtistID = (SELECT [ID] FROM [integration].[dbo].[tblMusic_Artist] WHERE [Artist] = @Artist)
INSERT INTO [integration].[dbo].[tblMusic_Song] ( [Song], [ArtistID], [AlbumID], [SLink])
VALUES ( @Song, @NewArtistID, @NewAlbumID, @SLink) END END ELSE BEGIN SET @NewAlbumID = (SELECT [ID] FROM [integration].[dbo].[tblMusic_Album] WHERE [Album] = @Album) SET @NewArtistID = (SELECT [ID] FROM [integration].[dbo].[tblMusic_Artist] WHERE [Artist] = @Artist)
INSERT INTO [integration].[dbo].[tblMusic_Song] ( [Song], [ArtistID], [AlbumID], [SLink])
VALUES ( @Song, @NewArtistID, @NewAlbumID, @SLink) END
May I know what does the syntax of inserting data into a field of type Unique Identifier look like?
[code] INSERT INTO THAI_MK_MT_Log(GUID, Status) VALUES ('2331486348632', 'S') [/code]
The "2331486348632" is to be inserted into a unique identifier field. If i coded the insert statement as the above, I got an error saying that "Syntax error converting from a character string to uniqueidentifier".....
i have migrated a DTS package wherein it consists of SQL task.
this has been migrated succesfully. but when i execute the package, i am getting the error with Excute SQL task which consists of Store Procedure excution.
But the SP can executed in the client server. can any body help in this regard.
Hi, all I'm getting this error at runtime when my page tries to populate a datagrid. Here's the relevant code. First, the user selects his choice from a dropdownlist, populated with a sqldatasource control on the aspx side:<asp:SqlDataSource ID="sqlDataSourceCompany" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [PayrollCompanyID], [DisplayName] FROM [rsrc_PayrollCompany] ORDER BY [DisplayName]"> </asp:SqlDataSource> And the dropdown list's code:<asp:DropDownList ID="ddlPayrollCompany" runat="server" AutoPostBack="True" DataSourceID="sqlDataSourcePayrollCompany" DataTextField="DisplayName" DataValueField="PayrollCompanyID"> </asp:DropDownList> Then, I use the selectedindexchanged event to bind the data to the datagrid. Here's that code: 1 Sub BindData() 2 3 Dim ds As New DataSet 4 Dim sda As SqlClient.SqlDataAdapter 5 Dim strSQL As String 6 Dim strCon As String 7 8 strSQL = "SELECT [SocialSecurityNumber], [Prefix], [FirstName], [LastName], [HireDate], [PayrollCostPercent], " & _ 9 "[Phone], [BadgeNumber], [IsSupervisor], [SupervisorID], [IsUser], [IsScout] FROM [rsrc_Personnel] " & _ 10 "WHERE ([PayrollCompanyID] = @PayrollCompanyID)" 11 12 strCon = "Data Source=DATASOURCE;Initial Catalog=DATABASE;User ID=USERID;Password=PASSWORD" 13 14 sda = New SqlClient.SqlDataAdapter(strSQL, strCon) 15 16 sda.SelectCommand.Parameters.Add(New SqlClient.SqlParameter("@PayrollCompanyID", Me.ddlPayrollCompany.SelectedItem.ToString())) 17 18 sda.Fill(ds, "rsrc_Personnel") 19 20 dgPersonnel.DataSource = ds.Tables("rsrc_Personnel") 21 dgPersonnel.DataBind() 22 23 End Sub 24
I'm assuming my problem lies in line 16 of the above code. I've tried SelectedItemIndex, SelectedItemValue too and get errors for those, as well. What am I missing? Thanks for anyone's help! Cappela07