Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

Monday, March 26, 2012

Error 17066

In the last week we are seeing several occurrences of the following error:
Error 602, Severity 21, State 30:
Could not find an entry for table or index with partitionID 189907171868672 in database 2.

This is always followed by a stack dump and this error:
SQL Server Assertion: File: <qxcntxt.cpp>, line = 1069 Failed Assertion = 'cref == 0'.

I have run checkdb on tempdb and no errors are reported. Additionally, we have dropped and recreated the sp indicated in the stack dump. The errors continue.

We are running 64 bit SQL 2005 with sp2.

HELP!!!!!!!!!!!!!!!!!!!!!!!!!!

Stack dump normally means a bug in sqlserver. It's best to contact PSS to get it resolved.

Wednesday, March 21, 2012

Error 14262

Merge replication - SQL 2000. I ran some scripts to add a column to a table
and to add a new table and view to articles. All went fine. Then I tried
to manually start the snapshot agent and it gave me this error "The
specified @.job_id('guid number...') does not exist."
What do I need to do? I looked at Paul's site and found the explanation but
I'm not sure if this applies and was not clear what to do. Please help,
thanks.
David
Hi David - the explanation on my site refers to a scripting error and
doesn't seem relevant to your case to be honest. Can you refresh the jobs
folder as I think that you might be attempting to start a job that has been
removed/replaced. Also check under replication monitor that the agent has a
job (right-click and select "Agent properties..." and see what the name is
there.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com .
|||Paul,
I got this message from the Snapshot Agents folder, right-click of the
publication (which has a red X on it) and selecting "Start Agent". The
status column shows "Failed" due to "Timeout expired. ..." Apparently the
last attempt to create this had a problem. This server is not on our site,
so I'm not sure what happened. Also, this publication under the Publishers
folder also has a red X on it. Do I have to re-create the Publication
entirely?
Also, when I was there yesterday I created a new table and added it to the
articles via sp_addmergearticle. I also ran sp_repladdcolumn to add a
column to an existing publication. I have 2 publications, one for tables
and the other for views and stored procs. The one with the problems is the
tables publication and these problems (red X) existed before I ran these
additions.
David
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:egCdwmKMHHA.4000@.TK2MSFTNGP06.phx.gbl...
> Hi David - the explanation on my site refers to a scripting error and
> doesn't seem relevant to your case to be honest. Can you refresh the jobs
> folder as I think that you might be attempting to start a job that has
> been removed/replaced. Also check under replication monitor that the agent
> has a job (right-click and select "Agent properties..." and see what the
> name is there.
> Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com .
>

Sunday, March 11, 2012

Error 120

Hello.
I'm trying to run the following statement:
insert into [destination table]
([fields])
select [fields] from [source table]
When I try to run it, I get the following error messages:
Server: Msg 120, Level 15, State 1, Line 8
The select list for the INSERT statement contains fewer
items than the insert list. The number of SELECT values
must match the number of INSERT columns.
Server: Msg 8180, Level 16, State 1, Line 8
Statement(s) could not be prepared.
The select list matches the insert list exactly.
The source and destination tables are located on two
different (linked) servers.
Both servers are running MSSQL 2000 SP3a.
What am I doing wrong?
Thank you.Without seeing the actual insert statement we can only guess. My guess
would be you have a space in one of the column names.
Andrew J. Kelly
SQL Server MVP
"Vlad Soare" <vsoare@.hotmail.com> wrote in message
news:12a5601c4432a$dcaeb0e0$a301280a@.phx
.gbl...
> Hello.
> I'm trying to run the following statement:
> insert into [destination table]
> ([fields])
> select [fields] from [source table]
> When I try to run it, I get the following error messages:
> Server: Msg 120, Level 15, State 1, Line 8
> The select list for the INSERT statement contains fewer
> items than the insert list. The number of SELECT values
> must match the number of INSERT columns.
> Server: Msg 8180, Level 16, State 1, Line 8
> Statement(s) could not be prepared.
> The select list matches the insert list exactly.
> The source and destination tables are located on two
> different (linked) servers.
> Both servers are running MSSQL 2000 SP3a.
> What am I doing wrong?
> Thank you.
>|||No, the statement is definitely OK, it works on other
servers, there's only one server it doesn't work on. And
it works if I run it locally, but it doesn't work when I
run it from another server.
Here are the statements:
declare @.IdSpatiu int,
@.IdTran int
set @.IdSpatiu = 15
set @.IdTran = 20
insert into [ts-331].Ploiesti.dbo.Factura
(IdSpatiu, IdTran, Numar)
select @.IdSpatiu, @.IdTran, Numar
from [ts-331].Deva.dbo.Factura
where IdTran = 11 and IdSpatiu = 9
If I replace "select @.IdSpatiu, @.IdTran, Numar"
with "select 15, 20, Numar", it works. It doesn't like
the variables in the select list.
If I'm connected to the server [ts-331], it works. But if
I'm connected to another server (to which ts-331 is
linked), it doesn't work.
It must be something about the ts-331 server. At first I
thought it must be the service pack, because it had no
service pack installed, but then I installed SP3a and the
problem persisted.
Thank you.

>--Original Message--
>Without seeing the actual insert statement we can only
guess. My guess
>would be you have a space in one of the column names.
>--|||It looks fine to me as well. Maybe there is something strange with the way
the Linked server is set up on that machine. Why do you want to do an
insert like that remotely anyway? It would be much cleaner if you had a
stored proc on the linked server that you call and pass in the 2 parameters.
That way the sp does not have to make any linked server calls at all when
actually doing the Insert.
Andrew J. Kelly
SQL Server MVP
"Vlad Soare" <vsoare@.hotmail.com> wrote in message
news:1318b01c443b8$d05fa8b0$a401280a@.phx
.gbl...
> No, the statement is definitely OK, it works on other
> servers, there's only one server it doesn't work on. And
> it works if I run it locally, but it doesn't work when I
> run it from another server.
> Here are the statements:
> declare @.IdSpatiu int,
> @.IdTran int
> set @.IdSpatiu = 15
> set @.IdTran = 20
> insert into [ts-331].Ploiesti.dbo.Factura
> (IdSpatiu, IdTran, Numar)
> select @.IdSpatiu, @.IdTran, Numar
> from [ts-331].Deva.dbo.Factura
> where IdTran = 11 and IdSpatiu = 9
> If I replace "select @.IdSpatiu, @.IdTran, Numar"
> with "select 15, 20, Numar", it works. It doesn't like
> the variables in the select list.
> If I'm connected to the server [ts-331], it works. But if
> I'm connected to another server (to which ts-331 is
> linked), it doesn't work.
> It must be something about the ts-331 server. At first I
> thought it must be the service pack, because it had no
> service pack installed, but then I installed SP3a and the
> problem persisted.
> Thank you.
>
> guess. My guess
>|||I had the same problem. Try this. I don't know why it works but it
does.
insert into [ts-331].Ploiesti.dbo.Factura
(IdSpatiu, IdTran, Numar)
select (select @.IdSpatiu), (select @.IdTran), Numar
from [ts-331].Deva.dbo.Factura
where IdTran = 11 and IdSpatiu = 9

Error 120

Hello.
I'm trying to run the following statement:
insert into [destination table]
([fields])
select [fields] from [source table]
When I try to run it, I get the following error messages:
Server: Msg 120, Level 15, State 1, Line 8
The select list for the INSERT statement contains fewer
items than the insert list. The number of SELECT values
must match the number of INSERT columns.
Server: Msg 8180, Level 16, State 1, Line 8
Statement(s) could not be prepared.
The select list matches the insert list exactly.
The source and destination tables are located on two
different (linked) servers.
Both servers are running MSSQL 2000 SP3a.
What am I doing wrong?
Thank you.
Without seeing the actual insert statement we can only guess. My guess
would be you have a space in one of the column names.
Andrew J. Kelly
SQL Server MVP
"Vlad Soare" <vsoare@.hotmail.com> wrote in message
news:12a5601c4432a$dcaeb0e0$a301280a@.phx.gbl...
> Hello.
> I'm trying to run the following statement:
> insert into [destination table]
> ([fields])
> select [fields] from [source table]
> When I try to run it, I get the following error messages:
> Server: Msg 120, Level 15, State 1, Line 8
> The select list for the INSERT statement contains fewer
> items than the insert list. The number of SELECT values
> must match the number of INSERT columns.
> Server: Msg 8180, Level 16, State 1, Line 8
> Statement(s) could not be prepared.
> The select list matches the insert list exactly.
> The source and destination tables are located on two
> different (linked) servers.
> Both servers are running MSSQL 2000 SP3a.
> What am I doing wrong?
> Thank you.
>
|||No, the statement is definitely OK, it works on other
servers, there's only one server it doesn't work on. And
it works if I run it locally, but it doesn't work when I
run it from another server.
Here are the statements:
declare @.IdSpatiu int,
@.IdTran int
set @.IdSpatiu = 15
set @.IdTran = 20
insert into [ts-331].Ploiesti.dbo.Factura
(IdSpatiu, IdTran, Numar)
select @.IdSpatiu, @.IdTran, Numar
from [ts-331].Deva.dbo.Factura
where IdTran = 11 and IdSpatiu = 9
If I replace "select @.IdSpatiu, @.IdTran, Numar"
with "select 15, 20, Numar", it works. It doesn't like
the variables in the select list.
If I'm connected to the server [ts-331], it works. But if
I'm connected to another server (to which ts-331 is
linked), it doesn't work.
It must be something about the ts-331 server. At first I
thought it must be the service pack, because it had no
service pack installed, but then I installed SP3a and the
problem persisted.
Thank you.

>--Original Message--
>Without seeing the actual insert statement we can only
guess. My guess
>would be you have a space in one of the column names.
>--
|||It looks fine to me as well. Maybe there is something strange with the way
the Linked server is set up on that machine. Why do you want to do an
insert like that remotely anyway? It would be much cleaner if you had a
stored proc on the linked server that you call and pass in the 2 parameters.
That way the sp does not have to make any linked server calls at all when
actually doing the Insert.
Andrew J. Kelly
SQL Server MVP
"Vlad Soare" <vsoare@.hotmail.com> wrote in message
news:1318b01c443b8$d05fa8b0$a401280a@.phx.gbl...
> No, the statement is definitely OK, it works on other
> servers, there's only one server it doesn't work on. And
> it works if I run it locally, but it doesn't work when I
> run it from another server.
> Here are the statements:
> declare @.IdSpatiu int,
> @.IdTran int
> set @.IdSpatiu = 15
> set @.IdTran = 20
> insert into [ts-331].Ploiesti.dbo.Factura
> (IdSpatiu, IdTran, Numar)
> select @.IdSpatiu, @.IdTran, Numar
> from [ts-331].Deva.dbo.Factura
> where IdTran = 11 and IdSpatiu = 9
> If I replace "select @.IdSpatiu, @.IdTran, Numar"
> with "select 15, 20, Numar", it works. It doesn't like
> the variables in the select list.
> If I'm connected to the server [ts-331], it works. But if
> I'm connected to another server (to which ts-331 is
> linked), it doesn't work.
> It must be something about the ts-331 server. At first I
> thought it must be the service pack, because it had no
> service pack installed, but then I installed SP3a and the
> problem persisted.
> Thank you.
> guess. My guess
>
|||I had the same problem. Try this. I don't know why it works but it
does.
insert into [ts-331].Ploiesti.dbo.Factura
(IdSpatiu, IdTran, Numar)
select (select @.IdSpatiu), (select @.IdTran), Numar
from [ts-331].Deva.dbo.Factura
where IdTran = 11 and IdSpatiu = 9

Error 120

Hello.
I'm trying to run the following statement:
insert into [destination table]
([fields])
select [fields] from [source table]
When I try to run it, I get the following error messages:
Server: Msg 120, Level 15, State 1, Line 8
The select list for the INSERT statement contains fewer
items than the insert list. The number of SELECT values
must match the number of INSERT columns.
Server: Msg 8180, Level 16, State 1, Line 8
Statement(s) could not be prepared.
The select list matches the insert list exactly.
The source and destination tables are located on two
different (linked) servers.
Both servers are running MSSQL 2000 SP3a.
What am I doing wrong?
Thank you.Without seeing the actual insert statement we can only guess. My guess
would be you have a space in one of the column names.
--
Andrew J. Kelly
SQL Server MVP
"Vlad Soare" <vsoare@.hotmail.com> wrote in message
news:12a5601c4432a$dcaeb0e0$a301280a@.phx.gbl...
> Hello.
> I'm trying to run the following statement:
> insert into [destination table]
> ([fields])
> select [fields] from [source table]
> When I try to run it, I get the following error messages:
> Server: Msg 120, Level 15, State 1, Line 8
> The select list for the INSERT statement contains fewer
> items than the insert list. The number of SELECT values
> must match the number of INSERT columns.
> Server: Msg 8180, Level 16, State 1, Line 8
> Statement(s) could not be prepared.
> The select list matches the insert list exactly.
> The source and destination tables are located on two
> different (linked) servers.
> Both servers are running MSSQL 2000 SP3a.
> What am I doing wrong?
> Thank you.
>|||No, the statement is definitely OK, it works on other
servers, there's only one server it doesn't work on. And
it works if I run it locally, but it doesn't work when I
run it from another server.
Here are the statements:
declare @.IdSpatiu int,
@.IdTran int
set @.IdSpatiu = 15
set @.IdTran = 20
insert into [ts-331].Ploiesti.dbo.Factura
(IdSpatiu, IdTran, Numar)
select @.IdSpatiu, @.IdTran, Numar
from [ts-331].Deva.dbo.Factura
where IdTran = 11 and IdSpatiu = 9
If I replace "select @.IdSpatiu, @.IdTran, Numar"
with "select 15, 20, Numar", it works. It doesn't like
the variables in the select list.
If I'm connected to the server [ts-331], it works. But if
I'm connected to another server (to which ts-331 is
linked), it doesn't work.
It must be something about the ts-331 server. At first I
thought it must be the service pack, because it had no
service pack installed, but then I installed SP3a and the
problem persisted.
Thank you.
>--Original Message--
>Without seeing the actual insert statement we can only
guess. My guess
>would be you have a space in one of the column names.
>--|||It looks fine to me as well. Maybe there is something strange with the way
the Linked server is set up on that machine. Why do you want to do an
insert like that remotely anyway? It would be much cleaner if you had a
stored proc on the linked server that you call and pass in the 2 parameters.
That way the sp does not have to make any linked server calls at all when
actually doing the Insert.
--
Andrew J. Kelly
SQL Server MVP
"Vlad Soare" <vsoare@.hotmail.com> wrote in message
news:1318b01c443b8$d05fa8b0$a401280a@.phx.gbl...
> No, the statement is definitely OK, it works on other
> servers, there's only one server it doesn't work on. And
> it works if I run it locally, but it doesn't work when I
> run it from another server.
> Here are the statements:
> declare @.IdSpatiu int,
> @.IdTran int
> set @.IdSpatiu = 15
> set @.IdTran = 20
> insert into [ts-331].Ploiesti.dbo.Factura
> (IdSpatiu, IdTran, Numar)
> select @.IdSpatiu, @.IdTran, Numar
> from [ts-331].Deva.dbo.Factura
> where IdTran = 11 and IdSpatiu = 9
> If I replace "select @.IdSpatiu, @.IdTran, Numar"
> with "select 15, 20, Numar", it works. It doesn't like
> the variables in the select list.
> If I'm connected to the server [ts-331], it works. But if
> I'm connected to another server (to which ts-331 is
> linked), it doesn't work.
> It must be something about the ts-331 server. At first I
> thought it must be the service pack, because it had no
> service pack installed, but then I installed SP3a and the
> problem persisted.
> Thank you.
> >--Original Message--
> >Without seeing the actual insert statement we can only
> guess. My guess
> >would be you have a space in one of the column names.
> >
> >--
>|||I had the same problem. Try this. I don't know why it works but it
does.
insert into [ts-331].Ploiesti.dbo.Factura
(IdSpatiu, IdTran, Numar)
select (select @.IdSpatiu), (select @.IdTran), Numar
from [ts-331].Deva.dbo.Factura
where IdTran = 11 and IdSpatiu = 9

Error 1105: 'PRIMARY' filegroup is full

I get the following error when attempting to run the
Database Maintenance Plan Optimization job for a database:
Rebuilding indexes for table 'WebLog'
[Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 1105:
[Microsoft][ODBC SQL Server Driver][SQL Server]Could not
allocate space for object '(SYSTEM table id: -933813458)'
in database 'svc2000WebLog' because the 'PRIMARY'
filegroup is full.
I am running SQL Server 2000 (SP3) on a Windows 2000 (SP4)
machine. There is plenty of disk space on the server. Do
I need to expand the database before running this job?SQL Server need working space in the db for DBCC DBREINDEX. Also, autogrow
doesn't catch up in some situations. See below. Consider pre-allocating
storage or using DBCC INDEXDEFRAG instead.
http://support.microsoft.com/default.aspx?scid=kb;en-us;305635
--
Tibor Karaszi
"Tom Griffin" <griffin@.co.santa-barbara.ca.us> wrote in message
news:042601c3a23d$5e190a70$a301280a@.phx.gbl...
> I get the following error when attempting to run the
> Database Maintenance Plan Optimization job for a database:
> Rebuilding indexes for table 'WebLog'
> [Microsoft SQL-DMO (ODBC SQLState: 42000)] Error 1105:
> [Microsoft][ODBC SQL Server Driver][SQL Server]Could not
> allocate space for object '(SYSTEM table id: -933813458)'
> in database 'svc2000WebLog' because the 'PRIMARY'
> filegroup is full.
> I am running SQL Server 2000 (SP3) on a Windows 2000 (SP4)
> machine. There is plenty of disk space on the server. Do
> I need to expand the database before running this job?
>

Friday, March 9, 2012

error 1012: the correlation name % has the same exposed name as table %.

Im trying to find the error in this statement:

CREATE PROCEDURE STP_selectmain

AS

select a.inventoryid, b.firstname, b.lastname, art.title, art.medium,
a.cost, a.inventoryid, a.receivedate, a.dimensions,
a.reference, art.provenance, sum(c.restorationcost),
sum(d.framingcost), sum(e.cost)
from art as a left outer join artist as b on a.artistid =
b.artistid,
a left outer join restoration as c on a.inventoryid =
c.inventoryid,
a left outer join outframing as d on a.inventoryid =
d.inventoryid,
a left outer join basiccosts as e on a.inventoryid =
e.inventoryid

group by a.inventoryid, b.firstname, b.lastname, a.title, a.medium,
a.cost, a.inventoryid, a.receivedate, a.dimensions, a.reference,
a.provenance
order by a.inventoryid desc
GO

eveytime I do a syntax check on it I get this error.

error 1012: the correlation name 'a' has the same exposed name as
table 'a'.

Whats the syntax to fix this?

thanks

-JimJim (jim.ferris@.motorola.com) writes:
> select a.inventoryid, b.firstname, b.lastname, art.title, art.medium,
> a.cost, a.inventoryid, a.receivedate, a.dimensions,
> a.reference, art.provenance, sum(c.restorationcost),
> sum(d.framingcost), sum(e.cost)
> from art as a left outer join artist as b on a.artistid =
> b.artistid,
> a left outer join restoration as c on a.inventoryid =
> c.inventoryid,
> a left outer join outframing as d on a.inventoryid =
> d.inventoryid,
> a left outer join basiccosts as e on a.inventoryid =
> e.inventoryid
> group by a.inventoryid, b.firstname, b.lastname, a.title, a.medium,
> a.cost, a.inventoryid, a.receivedate, a.dimensions, a.reference,
> a.provenance
> order by a.inventoryid desc
> GO
>...
> error 1012: the correlation name 'a' has the same exposed name as
> table 'a'.
> Whats the syntax to fix this?

You have a mix of old and new FROM syntax, and I would suppose that
you mean:

FROM art AS a
LEFT JOIN artist AS b ON a.artistid = b.artistid
LEFT JOIN restoration AS c ON a.inventoryid = c.inventoryid
LEFT JOIN outframing AS d ON a.inventoryid = d.inventoryid
LEFT JOIN asiccosts AS e on a.inventoryid = e.inventoryid

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Wednesday, March 7, 2012

Error 07002 - SQLBindParameter not used for all parameters

Hi, I created a simple VB.NET 2003 application through Visual Studio
that connects to a MySQL database and loads a table into a Dataset, and
then displays that table information in a DataGrid on a form for
editing. The table fill works fine, the delete function works fine, but
when I try to update a row, the application fails with the following
error message:
An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred
in system.data.dll
Additional information: System error.
'Data Access VB App.exe': Loaded
'c:\windows\assembly\gac\microsoft.visualbasic\7.0 .5000.0__b03f5f7f11d50
a3a\microsoft.visualbasic.dll', No symbols loaded.
Unhandled Exception: System.Data.Odbc.OdbcException: ERROR [07002]
[MySQL][ODBC 3.51 Driver][mysqld-4.0.21-debug]SQLBindParameter not used
for all parameters
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet)
at Data_Access_VB_App.Form1.btnUpdate_Click(Object sender, EventArgs
e) in C:\Documents and Settings\System Admin\My Documents\Visual Studio
Projects\Data Access VB App\Form1.vb:line 225
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProThe program '[2608] Data Access
VB App.exe' has exited with code 0 (0x0).
c(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeM
ethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32
reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Data_Access_VB_App.Form1.Main() in C:\Documents and
Settings\System Admin\My Documents\Visual Studio Projects\Data Access VB
App\Form1.vb:line 1
The majority of the code was generated by Visual Studio and based on the
error message it would seem that I have to add SQLBindParameter
statements, but I am not sure the syntax that I should be using. I am
new to VB.NET (coming from Java/J2EE) and haven't been able to come up
with a workable solution after pouring over the MSDN manuals. Here is
the generated code:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents OdbcDataAdapter1 As
System.Data.Odbc.OdbcDataAdapter
Friend WithEvents OdbcConnection1 As System.Data.Odbc.OdbcConnection
Friend WithEvents DsTags1 As Data_Access_VB_App.dsTags
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents btnUpdate As System.Windows.Forms.Button
Friend WithEvents btnLoad As System.Windows.Forms.Button
Friend WithEvents OdbcDataAdapter2 As
System.Data.Odbc.OdbcDataAdapter
Friend WithEvents OdbcSelectCommand2 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcInsertCommand2 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcConnection2 As System.Data.Odbc.OdbcConnection
Friend WithEvents OdbcDeleteCommand2 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcUpdateCommand2 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcSelectCommand1 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcInsertCommand1 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcDeleteCommand1 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcUpdateCommand1 As System.Data.Odbc.OdbcCommand
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.OdbcDataAdapter1 = New System.Data.Odbc.OdbcDataAdapter
Me.OdbcConnection1 = New System.Data.Odbc.OdbcConnection
Me.DsTags1 = New Data_Access_VB_App.dsTags
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.btnUpdate = New System.Windows.Forms.Button
Me.btnLoad = New System.Windows.Forms.Button
Me.OdbcDataAdapter2 = New System.Data.Odbc.OdbcDataAdapter
Me.OdbcDeleteCommand2 = New System.Data.Odbc.OdbcCommand
Me.OdbcConnection2 = New System.Data.Odbc.OdbcConnection
Me.OdbcInsertCommand2 = New System.Data.Odbc.OdbcCommand
Me.OdbcSelectCommand2 = New System.Data.Odbc.OdbcCommand
Me.OdbcUpdateCommand2 = New System.Data.Odbc.OdbcCommand
Me.OdbcSelectCommand1 = New System.Data.Odbc.OdbcCommand
Me.OdbcInsertCommand1 = New System.Data.Odbc.OdbcCommand
Me.OdbcDeleteCommand1 = New System.Data.Odbc.OdbcCommand
Me.OdbcUpdateCommand1 = New System.Data.Odbc.OdbcCommand
CType(Me.DsTags1,
System.ComponentModel.ISupportInitialize).BeginIni t()
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).BeginIni t()
Me.SuspendLayout()
'
'OdbcDataAdapter1
'
Me.OdbcDataAdapter1.DeleteCommand = Me.OdbcDeleteCommand1
Me.OdbcDataAdapter1.InsertCommand = Me.OdbcInsertCommand1
Me.OdbcDataAdapter1.SelectCommand = Me.OdbcSelectCommand1
Me.OdbcDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "epctag", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("ID", "ID"), New
System.Data.Common.DataColumnMapping("OBJECT_EPC", "OBJECT_EPC"), New
System.Data.Common.DataColumnMapping("READER_EPC", "READER_EPC"), New
System.Data.Common.DataColumnMapping("DATE_TIME", "DATE_TIME"), New
System.Data.Common.DataColumnMapping("PAYLOAD", "PAYLOAD"), New
System.Data.Common.DataColumnMapping("GTIN_DOMAIN" , "GTIN_DOMAIN"), New
System.Data.Common.DataColumnMapping("GTIN_CLASS", "GTIN_CLASS")})})
Me.OdbcDataAdapter1.UpdateCommand = Me.OdbcUpdateCommand1
'
'OdbcConnection1
'
Me.OdbcConnection1.ConnectionString =
"STMT=;OPTION=3;DSN=EPCThingsNET;UID=root;SOCKET=; DESC=MySQL ODBC 3.51
Driver DSN;" & _
"DATABASE=thingsnet;SERVER=localhost;PORT=3306 "
'
'DsTags1
'
Me.DsTags1.DataSetName = "dsTags"
Me.DsTags1.Locale = New
System.Globalization.CultureInfo("en-US")
'
'DataGrid1
'
Me.DataGrid1.DataMember = "epctag"
Me.DataGrid1.DataSource = Me.DsTags1
Me.DataGrid1.HeaderForeColor =
System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(8, 128)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(584, 264)
Me.DataGrid1.TabIndex = 0
'
'btnUpdate
'
Me.btnUpdate.Location = New System.Drawing.Point(224, 48)
Me.btnUpdate.Name = "btnUpdate"
Me.btnUpdate.Size = New System.Drawing.Size(152, 23)
Me.btnUpdate.TabIndex = 1
Me.btnUpdate.Text = "Save Changes in Database"
'
'btnLoad
'
Me.btnLoad.Location = New System.Drawing.Point(56, 40)
Me.btnLoad.Name = "btnLoad"
Me.btnLoad.TabIndex = 2
Me.btnLoad.Text = "Load Data"
'
'OdbcSelectCommand1
'
Me.OdbcSelectCommand1.CommandText = "SELECT ID, OBJECT_EPC,
READER_EPC, DATE_TIME, PAYLOAD, GTIN_DOMAIN, GTIN_CLASS FR" & _
"OM epctag"
Me.OdbcSelectCommand1.Connection = Me.OdbcConnection1
'
'OdbcInsertCommand1
'
Me.OdbcInsertCommand1.CommandText = "INSERT INTO epctag(ID,
OBJECT_EPC, READER_EPC, DATE_TIME, PAYLOAD, GTIN_DOMAIN, G" & _
"TIN_CLASS) VALUES (?, ?, ?, ?, ?, ?, ?)"
Me.OdbcInsertCommand1.Connection = Me.OdbcConnection1
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
0, "ID"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("OBJECT_EPC",
System.Data.Odbc.OdbcType.VarChar, 255, "OBJECT_EPC"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("READER_EPC",
System.Data.Odbc.OdbcType.VarChar, 255, "READER_EPC"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("DATE_TIME",
System.Data.Odbc.OdbcType.VarChar, 255, "DATE_TIME"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("PAYLOAD",
System.Data.Odbc.OdbcType.VarChar, 255, "PAYLOAD"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("GTIN_DOMAIN",
System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_DOMAIN"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("GTIN_CLASS",
System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_CLASS"))
'
'OdbcDeleteCommand1
'
Me.OdbcDeleteCommand1.CommandText = "DELETE FROM epctag WHERE
(ID = ?)"
Me.OdbcDeleteCommand1.Connection = Me.OdbcConnection1
Me.OdbcDeleteCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "ID", System.Data.DataRowVersion.Original, Nothing))
'
'OdbcUpdateCommand1
'
Me.OdbcUpdateCommand1.CommandText = "UPDATE ecptag SET ID = ?,
OBJECT_EPC = ?, READER_EPC = ?, DATE_TIME = ?, PAYLOAD " & _
"= ?, GTIN_DOMAIN = ?, GTIN_CLASS = ? WHERE (ID = ?)"
Me.OdbcUpdateCommand1.Connection = Me.OdbcConnection1
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
0, "ID"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("OBJECT_EPC",
System.Data.Odbc.OdbcType.VarChar, 255, "OBJECT_EPC"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("READER_EPC",
System.Data.Odbc.OdbcType.VarChar, 255, "READER_EPC"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("DATE_TIME",
System.Data.Odbc.OdbcType.VarChar, 255, "DATE_TIME"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("PAYLOAD",
System.Data.Odbc.OdbcType.VarChar, 255, "PAYLOAD"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("GTIN_DOMAIN",
System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_DOMAIN"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("GTIN_CLASS",
System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_CLASS"))
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(608, 398)
Me.Controls.Add(Me.btnLoad)
Me.Controls.Add(Me.btnUpdate)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DsTags1,
System.ComponentModel.ISupportInitialize).EndInit( )
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).EndInit( )
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnUpdate.Click
OdbcDataAdapter1.Update(DsTags1)
MessageBox.Show("Database Updated!")
End Sub
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLoad.Click
OdbcDataAdapter1.Fill(DsTags1)
MessageBox.Show("Data Table Loaded Successfully!")
End Sub
End Class
That's the long and short of it! Appreciate any help.
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!
You aren't binding the correct number of parameters for the update command.
You are expecting ODBC to use the "ID" parameter twice, but that wont
happen. You have to bind an OdbcParameter object for each '?'. If you have
8 parameter markers, you must bind 8 parameters. You are only binding 7
parameters.
Brannon
"Mikey G" <nospam@.devdex.com> wrote in message
news:#M02y8hsEHA.2808@.TK2MSFTNGP14.phx.gbl...
> Hi, I created a simple VB.NET 2003 application through Visual Studio
> that connects to a MySQL database and loads a table into a Dataset, and
> then displays that table information in a DataGrid on a form for
> editing. The table fill works fine, the delete function works fine, but
> when I try to update a row, the application fails with the following
> error message:
> An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred
> in system.data.dll
> Additional information: System error.
> 'Data Access VB App.exe': Loaded
> 'c:\windows\assembly\gac\microsoft.visualbasic\7.0 .5000.0__b03f5f7f11d50
> a3a\microsoft.visualbasic.dll', No symbols loaded.
> Unhandled Exception: System.Data.Odbc.OdbcException: ERROR [07002]
> [MySQL][ODBC 3.51 Driver][mysqld-4.0.21-debug]SQLBindParameter not used
> for all parameters
> at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
> DataTableMapping tableMapping)
> at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
> srcTable)
> at System.Data.Common.DbDataAdapter.Update(DataSet dataSet)
> at Data_Access_VB_App.Form1.btnUpdate_Click(Object sender, EventArgs
> e) in C:\Documents and Settings\System Admin\My Documents\Visual Studio
> Projects\Data Access VB App\Form1.vb:line 225
> at System.Windows.Forms.Control.OnClick(EventArgs e)
> at System.Windows.Forms.Button.OnClick(EventArgs e)
> at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
> at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
> button, Int32 clicks)
> at System.Windows.Forms.Control.WndProc(Message& m)
> at System.Windows.Forms.ButtonBase.WndProc(Message& m)
> at System.Windows.Forms.Button.WndProThe program '[2608] Data Access
> VB App.exe' has exited with code 0 (0x0).
> c(Message& m)
> at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
> at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
> at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr hWnd,
> Int32 msg, IntPtr wparam, IntPtr lparam)
> at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
> msg)
> at
> System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeM
> ethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32
> reason, Int32 pvLoopData)
> at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32
> reason, ApplicationContext context)
> at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
> ApplicationContext context)
> at System.Windows.Forms.Application.Run(Form mainForm)
> at Data_Access_VB_App.Form1.Main() in C:\Documents and
> Settings\System Admin\My Documents\Visual Studio Projects\Data Access VB
> App\Form1.vb:line 1
>
> The majority of the code was generated by Visual Studio and based on the
> error message it would seem that I have to add SQLBindParameter
> statements, but I am not sure the syntax that I should be using. I am
> new to VB.NET (coming from Java/J2EE) and haven't been able to come up
> with a workable solution after pouring over the MSDN manuals. Here is
> the generated code:
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
> #Region " Windows Form Designer generated code "
> Public Sub New()
> MyBase.New()
> 'This call is required by the Windows Form Designer.
> InitializeComponent()
> 'Add any initialization after the InitializeComponent() call
> End Sub
> 'Form overrides dispose to clean up the component list.
> Protected Overloads Overrides Sub Dispose(ByVal disposing As
> Boolean)
> If disposing Then
> If Not (components Is Nothing) Then
> components.Dispose()
> End If
> End If
> MyBase.Dispose(disposing)
> End Sub
> 'NOTE: The following procedure is required by the Windows Form Designer
> 'It can be modified using the Windows Form Designer.
> 'Do not modify it using the code editor.
> Friend WithEvents OdbcDataAdapter1 As
> System.Data.Odbc.OdbcDataAdapter
> Friend WithEvents OdbcConnection1 As System.Data.Odbc.OdbcConnection
> Friend WithEvents DsTags1 As Data_Access_VB_App.dsTags
> Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
> Friend WithEvents btnUpdate As System.Windows.Forms.Button
> Friend WithEvents btnLoad As System.Windows.Forms.Button
> Friend WithEvents OdbcDataAdapter2 As
> System.Data.Odbc.OdbcDataAdapter
> Friend WithEvents OdbcSelectCommand2 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcInsertCommand2 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcConnection2 As System.Data.Odbc.OdbcConnection
> Friend WithEvents OdbcDeleteCommand2 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcUpdateCommand2 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcSelectCommand1 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcInsertCommand1 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcDeleteCommand1 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcUpdateCommand1 As System.Data.Odbc.OdbcCommand
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
> Me.OdbcDataAdapter1 = New System.Data.Odbc.OdbcDataAdapter
> Me.OdbcConnection1 = New System.Data.Odbc.OdbcConnection
> Me.DsTags1 = New Data_Access_VB_App.dsTags
> Me.DataGrid1 = New System.Windows.Forms.DataGrid
> Me.btnUpdate = New System.Windows.Forms.Button
> Me.btnLoad = New System.Windows.Forms.Button
> Me.OdbcDataAdapter2 = New System.Data.Odbc.OdbcDataAdapter
> Me.OdbcDeleteCommand2 = New System.Data.Odbc.OdbcCommand
> Me.OdbcConnection2 = New System.Data.Odbc.OdbcConnection
> Me.OdbcInsertCommand2 = New System.Data.Odbc.OdbcCommand
> Me.OdbcSelectCommand2 = New System.Data.Odbc.OdbcCommand
> Me.OdbcUpdateCommand2 = New System.Data.Odbc.OdbcCommand
> Me.OdbcSelectCommand1 = New System.Data.Odbc.OdbcCommand
> Me.OdbcInsertCommand1 = New System.Data.Odbc.OdbcCommand
> Me.OdbcDeleteCommand1 = New System.Data.Odbc.OdbcCommand
> Me.OdbcUpdateCommand1 = New System.Data.Odbc.OdbcCommand
> CType(Me.DsTags1,
> System.ComponentModel.ISupportInitialize).BeginIni t()
> CType(Me.DataGrid1,
> System.ComponentModel.ISupportInitialize).BeginIni t()
> Me.SuspendLayout()
> '
> 'OdbcDataAdapter1
> '
> Me.OdbcDataAdapter1.DeleteCommand = Me.OdbcDeleteCommand1
> Me.OdbcDataAdapter1.InsertCommand = Me.OdbcInsertCommand1
> Me.OdbcDataAdapter1.SelectCommand = Me.OdbcSelectCommand1
> Me.OdbcDataAdapter1.TableMappings.AddRange(New
> System.Data.Common.DataTableMapping() {New
> System.Data.Common.DataTableMapping("Table", "epctag", New
> System.Data.Common.DataColumnMapping() {New
> System.Data.Common.DataColumnMapping("ID", "ID"), New
> System.Data.Common.DataColumnMapping("OBJECT_EPC", "OBJECT_EPC"), New
> System.Data.Common.DataColumnMapping("READER_EPC", "READER_EPC"), New
> System.Data.Common.DataColumnMapping("DATE_TIME", "DATE_TIME"), New
> System.Data.Common.DataColumnMapping("PAYLOAD", "PAYLOAD"), New
> System.Data.Common.DataColumnMapping("GTIN_DOMAIN" , "GTIN_DOMAIN"), New
> System.Data.Common.DataColumnMapping("GTIN_CLASS", "GTIN_CLASS")})})
> Me.OdbcDataAdapter1.UpdateCommand = Me.OdbcUpdateCommand1
> '
> 'OdbcConnection1
> '
> Me.OdbcConnection1.ConnectionString =
> "STMT=;OPTION=3;DSN=EPCThingsNET;UID=root;SOCKET=; DESC=MySQL ODBC 3.51
> Driver DSN;" & _
> "DATABASE=thingsnet;SERVER=localhost;PORT=3306 "
> '
> 'DsTags1
> '
> Me.DsTags1.DataSetName = "dsTags"
> Me.DsTags1.Locale = New
> System.Globalization.CultureInfo("en-US")
> '
> 'DataGrid1
> '
> Me.DataGrid1.DataMember = "epctag"
> Me.DataGrid1.DataSource = Me.DsTags1
> Me.DataGrid1.HeaderForeColor =
> System.Drawing.SystemColors.ControlText
> Me.DataGrid1.Location = New System.Drawing.Point(8, 128)
> Me.DataGrid1.Name = "DataGrid1"
> Me.DataGrid1.Size = New System.Drawing.Size(584, 264)
> Me.DataGrid1.TabIndex = 0
> '
> 'btnUpdate
> '
> Me.btnUpdate.Location = New System.Drawing.Point(224, 48)
> Me.btnUpdate.Name = "btnUpdate"
> Me.btnUpdate.Size = New System.Drawing.Size(152, 23)
> Me.btnUpdate.TabIndex = 1
> Me.btnUpdate.Text = "Save Changes in Database"
> '
> 'btnLoad
> '
> Me.btnLoad.Location = New System.Drawing.Point(56, 40)
> Me.btnLoad.Name = "btnLoad"
> Me.btnLoad.TabIndex = 2
> Me.btnLoad.Text = "Load Data"
> '
> 'OdbcSelectCommand1
> '
> Me.OdbcSelectCommand1.CommandText = "SELECT ID, OBJECT_EPC,
> READER_EPC, DATE_TIME, PAYLOAD, GTIN_DOMAIN, GTIN_CLASS FR" & _
> "OM epctag"
> Me.OdbcSelectCommand1.Connection = Me.OdbcConnection1
> '
> 'OdbcInsertCommand1
> '
> Me.OdbcInsertCommand1.CommandText = "INSERT INTO epctag(ID,
> OBJECT_EPC, READER_EPC, DATE_TIME, PAYLOAD, GTIN_DOMAIN, G" & _
> "TIN_CLASS) VALUES (?, ?, ?, ?, ?, ?, ?)"
> Me.OdbcInsertCommand1.Connection = Me.OdbcConnection1
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
> 0, "ID"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("OBJECT_EPC",
> System.Data.Odbc.OdbcType.VarChar, 255, "OBJECT_EPC"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("READER_EPC",
> System.Data.Odbc.OdbcType.VarChar, 255, "READER_EPC"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("DATE_TIME",
> System.Data.Odbc.OdbcType.VarChar, 255, "DATE_TIME"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("PAYLOAD",
> System.Data.Odbc.OdbcType.VarChar, 255, "PAYLOAD"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("GTIN_DOMAIN",
> System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_DOMAIN"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("GTIN_CLASS",
> System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_CLASS"))
> '
> 'OdbcDeleteCommand1
> '
> Me.OdbcDeleteCommand1.CommandText = "DELETE FROM epctag WHERE
> (ID = ?)"
> Me.OdbcDeleteCommand1.Connection = Me.OdbcConnection1
> Me.OdbcDeleteCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
> 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
> Byte), "ID", System.Data.DataRowVersion.Original, Nothing))
> '
> 'OdbcUpdateCommand1
> '
> Me.OdbcUpdateCommand1.CommandText = "UPDATE ecptag SET ID = ?,
> OBJECT_EPC = ?, READER_EPC = ?, DATE_TIME = ?, PAYLOAD " & _
> "= ?, GTIN_DOMAIN = ?, GTIN_CLASS = ? WHERE (ID = ?)"
> Me.OdbcUpdateCommand1.Connection = Me.OdbcConnection1
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
> 0, "ID"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("OBJECT_EPC",
> System.Data.Odbc.OdbcType.VarChar, 255, "OBJECT_EPC"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("READER_EPC",
> System.Data.Odbc.OdbcType.VarChar, 255, "READER_EPC"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("DATE_TIME",
> System.Data.Odbc.OdbcType.VarChar, 255, "DATE_TIME"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("PAYLOAD",
> System.Data.Odbc.OdbcType.VarChar, 255, "PAYLOAD"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("GTIN_DOMAIN",
> System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_DOMAIN"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("GTIN_CLASS",
> System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_CLASS"))
> '
> 'Form1
> '
> Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
> Me.ClientSize = New System.Drawing.Size(608, 398)
> Me.Controls.Add(Me.btnLoad)
> Me.Controls.Add(Me.btnUpdate)
> Me.Controls.Add(Me.DataGrid1)
> Me.Name = "Form1"
> Me.Text = "Form1"
> CType(Me.DsTags1,
> System.ComponentModel.ISupportInitialize).EndInit( )
> CType(Me.DataGrid1,
> System.ComponentModel.ISupportInitialize).EndInit( )
> Me.ResumeLayout(False)
> End Sub
> #End Region
> Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles btnUpdate.Click
> OdbcDataAdapter1.Update(DsTags1)
> MessageBox.Show("Database Updated!")
> End Sub
> Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnLoad.Click
> OdbcDataAdapter1.Fill(DsTags1)
> MessageBox.Show("Data Table Loaded Successfully!")
> End Sub
> End Class
>
> That's the long and short of it! Appreciate any help.
>
> *** Sent via Developersdex http://www.codecomments.com ***
> Don't just participate in USENET...get rewarded for it!

Error 07002 - SQLBindParameter not used for all parameters

Hi, I created a simple VB.NET 2003 application through Visual Studio
that connects to a mysql database and loads a table into a Dataset, and
then displays that table information in a DataGrid on a form for
editing. The table fill works fine, the delete function works fine, but
when I try to update a row, the application fails with the following
error message:
An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred
in system.data.dll
Additional information: System error.
'Data Access VB App.exe': Loaded
'c:\windows\assembly\gac\microsoft.visualbasic\7.0.5000.0__b03f5f7f11d50
a3a\microsoft.visualbasic.dll', No symbols loaded.
Unhandled Exception: System.Data.Odbc.OdbcException: ERROR [07002]
[MySQL][ODBC 3.51 Driver][mysqld-4.0.21-debug]SQLBindParameter n
ot used
for all parameters
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet)
at Data_Access_VB_App.Form1.btnUpdate_Click(Object sender, EventArgs
e) in C:\Documents and Settings\System Admin\My Documents\Visual Studio
Projects\Data Access VB App\Form1.vb:line 225
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProThe program '[2608] Data Access
VB App.exe' has exited with code 0 (0x0).
c(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
msg)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeM
ethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32
reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Data_Access_VB_App.Form1.Main() in C:\Documents and
Settings\System Admin\My Documents\Visual Studio Projects\Data Access VB
App\Form1.vb:line 1
The majority of the code was generated by Visual Studio and based on the
error message it would seem that I have to add SQLBindParameter
statements, but I am not sure the syntax that I should be using. I am
new to VB.NET (coming from Java/J2EE) and haven't been able to come up
with a workable solution after pouring over the MSDN manuals. Here is
the generated code:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents OdbcDataAdapter1 As
System.Data.Odbc.OdbcDataAdapter
Friend WithEvents OdbcConnection1 As System.Data.Odbc.OdbcConnection
Friend WithEvents DsTags1 As Data_Access_VB_App.dsTags
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents btnUpdate As System.Windows.Forms.Button
Friend WithEvents btnLoad As System.Windows.Forms.Button
Friend WithEvents OdbcDataAdapter2 As
System.Data.Odbc.OdbcDataAdapter
Friend WithEvents OdbcSelectCommand2 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcInsertCommand2 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcConnection2 As System.Data.Odbc.OdbcConnection
Friend WithEvents OdbcDeleteCommand2 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcUpdateCommand2 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcSelectCommand1 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcInsertCommand1 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcDeleteCommand1 As System.Data.Odbc.OdbcCommand
Friend WithEvents OdbcUpdateCommand1 As System.Data.Odbc.OdbcCommand
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.OdbcDataAdapter1 = New System.Data.Odbc.OdbcDataAdapter
Me.OdbcConnection1 = New System.Data.Odbc.OdbcConnection
Me.DsTags1 = New Data_Access_VB_App.dsTags
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.btnUpdate = New System.Windows.Forms.Button
Me.btnLoad = New System.Windows.Forms.Button
Me.OdbcDataAdapter2 = New System.Data.Odbc.OdbcDataAdapter
Me.OdbcDeleteCommand2 = New System.Data.Odbc.OdbcCommand
Me.OdbcConnection2 = New System.Data.Odbc.OdbcConnection
Me.OdbcInsertCommand2 = New System.Data.Odbc.OdbcCommand
Me.OdbcSelectCommand2 = New System.Data.Odbc.OdbcCommand
Me.OdbcUpdateCommand2 = New System.Data.Odbc.OdbcCommand
Me.OdbcSelectCommand1 = New System.Data.Odbc.OdbcCommand
Me.OdbcInsertCommand1 = New System.Data.Odbc.OdbcCommand
Me.OdbcDeleteCommand1 = New System.Data.Odbc.OdbcCommand
Me.OdbcUpdateCommand1 = New System.Data.Odbc.OdbcCommand
CType(Me.DsTags1,
System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'OdbcDataAdapter1
'
Me.OdbcDataAdapter1.DeleteCommand = Me.OdbcDeleteCommand1
Me.OdbcDataAdapter1.InsertCommand = Me.OdbcInsertCommand1
Me.OdbcDataAdapter1.SelectCommand = Me.OdbcSelectCommand1
Me.OdbcDataAdapter1.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() {New
System.Data.Common.DataTableMapping("Table", "epctag", New
System.Data.Common.DataColumnMapping() {New
System.Data.Common.DataColumnMapping("ID", "ID"), New
System.Data.Common.DataColumnMapping("OBJECT_EPC", "OBJECT_EPC"), New
System.Data.Common.DataColumnMapping("READER_EPC", "READER_EPC"), New
System.Data.Common.DataColumnMapping("DATE_TIME", "DATE_TIME"), New
System.Data.Common.DataColumnMapping("PAYLOAD", "PAYLOAD"), New
System.Data.Common.DataColumnMapping("GTIN_DOMAIN", "GTIN_DOMAIN"), New
System.Data.Common.DataColumnMapping("GTIN_CLASS", "GTIN_CLASS")})})
Me.OdbcDataAdapter1.UpdateCommand = Me.OdbcUpdateCommand1
'
'OdbcConnection1
'
Me.OdbcConnection1.ConnectionString =
" STMT=;OPTION=3;DSN=EPCThingsNET;UID=root
;SOCKET=;DESC=MySQL ODBC 3.51
Driver DSN;" & _
" DATABASE=thingsnet;SERVER=localhost;PORT
=3306"
'
'DsTags1
'
Me.DsTags1.DataSetName = "dsTags"
Me.DsTags1.Locale = New
System.Globalization.CultureInfo("en-US")
'
'DataGrid1
'
Me.DataGrid1.DataMember = "epctag"
Me.DataGrid1.DataSource = Me.DsTags1
Me.DataGrid1.HeaderForeColor =
System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(8, 128)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(584, 264)
Me.DataGrid1.TabIndex = 0
'
'btnUpdate
'
Me.btnUpdate.Location = New System.Drawing.Point(224, 48)
Me.btnUpdate.Name = "btnUpdate"
Me.btnUpdate.Size = New System.Drawing.Size(152, 23)
Me.btnUpdate.TabIndex = 1
Me.btnUpdate.Text = "Save Changes in Database"
'
'btnLoad
'
Me.btnLoad.Location = New System.Drawing.Point(56, 40)
Me.btnLoad.Name = "btnLoad"
Me.btnLoad.TabIndex = 2
Me.btnLoad.Text = "Load Data"
'
'OdbcSelectCommand1
'
Me.OdbcSelectCommand1.CommandText = "SELECT ID, OBJECT_EPC,
READER_EPC, DATE_TIME, PAYLOAD, GTIN_DOMAIN, GTIN_CLASS FR" & _
"OM epctag"
Me.OdbcSelectCommand1.Connection = Me.OdbcConnection1
'
'OdbcInsertCommand1
'
Me.OdbcInsertCommand1.CommandText = "INSERT INTO epctag(ID,
OBJECT_EPC, READER_EPC, DATE_TIME, PAYLOAD, GTIN_DOMAIN, G" & _
"TIN_CLASS) VALUES (?, ?, ?, ?, ?, ?, ?)"
Me.OdbcInsertCommand1.Connection = Me.OdbcConnection1
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
0, "ID"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("OBJECT_EPC",
System.Data.Odbc.OdbcType.VarChar, 255, "OBJECT_EPC"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("READER_EPC",
System.Data.Odbc.OdbcType.VarChar, 255, "READER_EPC"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("DATE_TIME",
System.Data.Odbc.OdbcType.VarChar, 255, "DATE_TIME"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("PAYLOAD",
System.Data.Odbc.OdbcType.VarChar, 255, "PAYLOAD"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("GTIN_DOMAIN",
System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_DOMAIN"))
Me.OdbcInsertCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("GTIN_CLASS",
System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_CLASS"))
'
'OdbcDeleteCommand1
'
Me.OdbcDeleteCommand1.CommandText = "DELETE FROM epctag WHERE
(ID = ?)"
Me.OdbcDeleteCommand1.Connection = Me.OdbcConnection1
Me.OdbcDeleteCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
Byte), "ID", System.Data.DataRowVersion.Original, Nothing))
'
'OdbcUpdateCommand1
'
Me.OdbcUpdateCommand1.CommandText = "UPDATE ecptag SET ID = ?,
OBJECT_EPC = ?, READER_EPC = ?, DATE_TIME = ?, PAYLOAD " & _
"= ?, GTIN_DOMAIN = ?, GTIN_CLASS = ? WHERE (ID = ?)"
Me.OdbcUpdateCommand1.Connection = Me.OdbcConnection1
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
0, "ID"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("OBJECT_EPC",
System.Data.Odbc.OdbcType.VarChar, 255, "OBJECT_EPC"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("READER_EPC",
System.Data.Odbc.OdbcType.VarChar, 255, "READER_EPC"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("DATE_TIME",
System.Data.Odbc.OdbcType.VarChar, 255, "DATE_TIME"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("PAYLOAD",
System.Data.Odbc.OdbcType.VarChar, 255, "PAYLOAD"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("GTIN_DOMAIN",
System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_DOMAIN"))
Me.OdbcUpdateCommand1.Parameters.Add(New
System.Data.Odbc.OdbcParameter("GTIN_CLASS",
System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_CLASS"))
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(608, 398)
Me.Controls.Add(Me.btnLoad)
Me.Controls.Add(Me.btnUpdate)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DsTags1,
System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnUpdate.Click
OdbcDataAdapter1.Update(DsTags1)
MessageBox.Show("Database Updated!")
End Sub
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLoad.Click
OdbcDataAdapter1.Fill(DsTags1)
MessageBox.Show("Data Table Loaded Successfully!")
End Sub
End Class
That's the long and short of it! Appreciate any help.
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!You aren't binding the correct number of parameters for the update command.
You are expecting ODBC to use the "ID" parameter twice, but that wont
happen. You have to bind an OdbcParameter object for each '?'. If you have
8 parameter markers, you must bind 8 parameters. You are only binding 7
parameters.
Brannon
"Mikey G" <nospam@.devdex.com> wrote in message
news:#M02y8hsEHA.2808@.TK2MSFTNGP14.phx.gbl...
> Hi, I created a simple VB.NET 2003 application through Visual Studio
> that connects to a mysql database and loads a table into a Dataset, and
> then displays that table information in a DataGrid on a form for
> editing. The table fill works fine, the delete function works fine, but
> when I try to update a row, the application fails with the following
> error message:
> An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred
> in system.data.dll
> Additional information: System error.
> 'Data Access VB App.exe': Loaded
> 'c:\windows\assembly\gac\microsoft.visualbasic\7.0.5000.0__b03f5f7f11d50
> a3a\microsoft.visualbasic.dll', No symbols loaded.
> Unhandled Exception: System.Data.Odbc.OdbcException: ERROR [07002]
> [MySQL][ODBC 3.51 Driver][mysqld-4.0.21-debug]SQLBindParameter
not used
> for all parameters
> at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
> DataTableMapping tableMapping)
> at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
> srcTable)
> at System.Data.Common.DbDataAdapter.Update(DataSet dataSet)
> at Data_Access_VB_App.Form1.btnUpdate_Click(Object sender, EventArgs
> e) in C:\Documents and Settings\System Admin\My Documents\Visual Studio
> Projects\Data Access VB App\Form1.vb:line 225
> at System.Windows.Forms.Control.OnClick(EventArgs e)
> at System.Windows.Forms.Button.OnClick(EventArgs e)
> at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
> at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
> button, Int32 clicks)
> at System.Windows.Forms.Control.WndProc(Message& m)
> at System.Windows.Forms.ButtonBase.WndProc(Message& m)
> at System.Windows.Forms.Button.WndProThe program '[2608] Data Acces
s
> VB App.exe' has exited with code 0 (0x0).
> c(Message& m)
> at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
> at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
> at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
> Int32 msg, IntPtr wparam, IntPtr lparam)
> at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&
> msg)
> at
> System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeM
> ethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32
> reason, Int32 pvLoopData)
> at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32
> reason, ApplicationContext context)
> at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
> ApplicationContext context)
> at System.Windows.Forms.Application.Run(Form mainForm)
> at Data_Access_VB_App.Form1.Main() in C:\Documents and
> Settings\System Admin\My Documents\Visual Studio Projects\Data Access VB
> App\Form1.vb:line 1
>
> The majority of the code was generated by Visual Studio and based on the
> error message it would seem that I have to add SQLBindParameter
> statements, but I am not sure the syntax that I should be using. I am
> new to VB.NET (coming from Java/J2EE) and haven't been able to come up
> with a workable solution after pouring over the MSDN manuals. Here is
> the generated code:
>
> Public Class Form1
> Inherits System.Windows.Forms.Form
> #Region " Windows Form Designer generated code "
> Public Sub New()
> MyBase.New()
> 'This call is required by the Windows Form Designer.
> InitializeComponent()
> 'Add any initialization after the InitializeComponent() call
> End Sub
> 'Form overrides dispose to clean up the component list.
> Protected Overloads Overrides Sub Dispose(ByVal disposing As
> Boolean)
> If disposing Then
> If Not (components Is Nothing) Then
> components.Dispose()
> End If
> End If
> MyBase.Dispose(disposing)
> End Sub
> 'NOTE: The following procedure is required by the Windows Form Designer
> 'It can be modified using the Windows Form Designer.
> 'Do not modify it using the code editor.
> Friend WithEvents OdbcDataAdapter1 As
> System.Data.Odbc.OdbcDataAdapter
> Friend WithEvents OdbcConnection1 As System.Data.Odbc.OdbcConnection
> Friend WithEvents DsTags1 As Data_Access_VB_App.dsTags
> Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
> Friend WithEvents btnUpdate As System.Windows.Forms.Button
> Friend WithEvents btnLoad As System.Windows.Forms.Button
> Friend WithEvents OdbcDataAdapter2 As
> System.Data.Odbc.OdbcDataAdapter
> Friend WithEvents OdbcSelectCommand2 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcInsertCommand2 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcConnection2 As System.Data.Odbc.OdbcConnection
> Friend WithEvents OdbcDeleteCommand2 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcUpdateCommand2 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcSelectCommand1 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcInsertCommand1 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcDeleteCommand1 As System.Data.Odbc.OdbcCommand
> Friend WithEvents OdbcUpdateCommand1 As System.Data.Odbc.OdbcCommand
> <System.Diagnostics.DebuggerStepThrough()> Private Sub
> InitializeComponent()
> Me.OdbcDataAdapter1 = New System.Data.Odbc.OdbcDataAdapter
> Me.OdbcConnection1 = New System.Data.Odbc.OdbcConnection
> Me.DsTags1 = New Data_Access_VB_App.dsTags
> Me.DataGrid1 = New System.Windows.Forms.DataGrid
> Me.btnUpdate = New System.Windows.Forms.Button
> Me.btnLoad = New System.Windows.Forms.Button
> Me.OdbcDataAdapter2 = New System.Data.Odbc.OdbcDataAdapter
> Me.OdbcDeleteCommand2 = New System.Data.Odbc.OdbcCommand
> Me.OdbcConnection2 = New System.Data.Odbc.OdbcConnection
> Me.OdbcInsertCommand2 = New System.Data.Odbc.OdbcCommand
> Me.OdbcSelectCommand2 = New System.Data.Odbc.OdbcCommand
> Me.OdbcUpdateCommand2 = New System.Data.Odbc.OdbcCommand
> Me.OdbcSelectCommand1 = New System.Data.Odbc.OdbcCommand
> Me.OdbcInsertCommand1 = New System.Data.Odbc.OdbcCommand
> Me.OdbcDeleteCommand1 = New System.Data.Odbc.OdbcCommand
> Me.OdbcUpdateCommand1 = New System.Data.Odbc.OdbcCommand
> CType(Me.DsTags1,
> System.ComponentModel.ISupportInitialize).BeginInit()
> CType(Me.DataGrid1,
> System.ComponentModel.ISupportInitialize).BeginInit()
> Me.SuspendLayout()
> '
> 'OdbcDataAdapter1
> '
> Me.OdbcDataAdapter1.DeleteCommand = Me.OdbcDeleteCommand1
> Me.OdbcDataAdapter1.InsertCommand = Me.OdbcInsertCommand1
> Me.OdbcDataAdapter1.SelectCommand = Me.OdbcSelectCommand1
> Me.OdbcDataAdapter1.TableMappings.AddRange(New
> System.Data.Common.DataTableMapping() {New
> System.Data.Common.DataTableMapping("Table", "epctag", New
> System.Data.Common.DataColumnMapping() {New
> System.Data.Common.DataColumnMapping("ID", "ID"), New
> System.Data.Common.DataColumnMapping("OBJECT_EPC", "OBJECT_EPC"), New
> System.Data.Common.DataColumnMapping("READER_EPC", "READER_EPC"), New
> System.Data.Common.DataColumnMapping("DATE_TIME", "DATE_TIME"), New
> System.Data.Common.DataColumnMapping("PAYLOAD", "PAYLOAD"), New
> System.Data.Common.DataColumnMapping("GTIN_DOMAIN", "GTIN_DOMAIN"), New
> System.Data.Common.DataColumnMapping("GTIN_CLASS", "GTIN_CLASS")})})
> Me.OdbcDataAdapter1.UpdateCommand = Me.OdbcUpdateCommand1
> '
> 'OdbcConnection1
> '
> Me.OdbcConnection1.ConnectionString =
> " STMT=;OPTION=3;DSN=EPCThingsNET;UID=root
;SOCKET=;DESC=MySQL ODBC 3.51
> Driver DSN;" & _
> " DATABASE=thingsnet;SERVER=localhost;PORT
=3306"
> '
> 'DsTags1
> '
> Me.DsTags1.DataSetName = "dsTags"
> Me.DsTags1.Locale = New
> System.Globalization.CultureInfo("en-US")
> '
> 'DataGrid1
> '
> Me.DataGrid1.DataMember = "epctag"
> Me.DataGrid1.DataSource = Me.DsTags1
> Me.DataGrid1.HeaderForeColor =
> System.Drawing.SystemColors.ControlText
> Me.DataGrid1.Location = New System.Drawing.Point(8, 128)
> Me.DataGrid1.Name = "DataGrid1"
> Me.DataGrid1.Size = New System.Drawing.Size(584, 264)
> Me.DataGrid1.TabIndex = 0
> '
> 'btnUpdate
> '
> Me.btnUpdate.Location = New System.Drawing.Point(224, 48)
> Me.btnUpdate.Name = "btnUpdate"
> Me.btnUpdate.Size = New System.Drawing.Size(152, 23)
> Me.btnUpdate.TabIndex = 1
> Me.btnUpdate.Text = "Save Changes in Database"
> '
> 'btnLoad
> '
> Me.btnLoad.Location = New System.Drawing.Point(56, 40)
> Me.btnLoad.Name = "btnLoad"
> Me.btnLoad.TabIndex = 2
> Me.btnLoad.Text = "Load Data"
> '
> 'OdbcSelectCommand1
> '
> Me.OdbcSelectCommand1.CommandText = "SELECT ID, OBJECT_EPC,
> READER_EPC, DATE_TIME, PAYLOAD, GTIN_DOMAIN, GTIN_CLASS FR" & _
> "OM epctag"
> Me.OdbcSelectCommand1.Connection = Me.OdbcConnection1
> '
> 'OdbcInsertCommand1
> '
> Me.OdbcInsertCommand1.CommandText = "INSERT INTO epctag(ID,
> OBJECT_EPC, READER_EPC, DATE_TIME, PAYLOAD, GTIN_DOMAIN, G" & _
> "TIN_CLASS) VALUES (?, ?, ?, ?, ?, ?, ?)"
> Me.OdbcInsertCommand1.Connection = Me.OdbcConnection1
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
> 0, "ID"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("OBJECT_EPC",
> System.Data.Odbc.OdbcType.VarChar, 255, "OBJECT_EPC"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("READER_EPC",
> System.Data.Odbc.OdbcType.VarChar, 255, "READER_EPC"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("DATE_TIME",
> System.Data.Odbc.OdbcType.VarChar, 255, "DATE_TIME"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("PAYLOAD",
> System.Data.Odbc.OdbcType.VarChar, 255, "PAYLOAD"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("GTIN_DOMAIN",
> System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_DOMAIN"))
> Me.OdbcInsertCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("GTIN_CLASS",
> System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_CLASS"))
> '
> 'OdbcDeleteCommand1
> '
> Me.OdbcDeleteCommand1.CommandText = "DELETE FROM epctag WHERE
> (ID = ?)"
> Me.OdbcDeleteCommand1.Connection = Me.OdbcConnection1
> Me.OdbcDeleteCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
> 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0,
> Byte), "ID", System.Data.DataRowVersion.Original, Nothing))
> '
> 'OdbcUpdateCommand1
> '
> Me.OdbcUpdateCommand1.CommandText = "UPDATE ecptag SET ID = ?,
> OBJECT_EPC = ?, READER_EPC = ?, DATE_TIME = ?, PAYLOAD " & _
> "= ?, GTIN_DOMAIN = ?, GTIN_CLASS = ? WHERE (ID = ?)"
> Me.OdbcUpdateCommand1.Connection = Me.OdbcConnection1
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("ID", System.Data.Odbc.OdbcType.BigInt,
> 0, "ID"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("OBJECT_EPC",
> System.Data.Odbc.OdbcType.VarChar, 255, "OBJECT_EPC"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("READER_EPC",
> System.Data.Odbc.OdbcType.VarChar, 255, "READER_EPC"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("DATE_TIME",
> System.Data.Odbc.OdbcType.VarChar, 255, "DATE_TIME"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("PAYLOAD",
> System.Data.Odbc.OdbcType.VarChar, 255, "PAYLOAD"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("GTIN_DOMAIN",
> System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_DOMAIN"))
> Me.OdbcUpdateCommand1.Parameters.Add(New
> System.Data.Odbc.OdbcParameter("GTIN_CLASS",
> System.Data.Odbc.OdbcType.VarChar, 255, "GTIN_CLASS"))
> '
> 'Form1
> '
> Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
> Me.ClientSize = New System.Drawing.Size(608, 398)
> Me.Controls.Add(Me.btnLoad)
> Me.Controls.Add(Me.btnUpdate)
> Me.Controls.Add(Me.DataGrid1)
> Me.Name = "Form1"
> Me.Text = "Form1"
> CType(Me.DsTags1,
> System.ComponentModel.ISupportInitialize).EndInit()
> CType(Me.DataGrid1,
> System.ComponentModel.ISupportInitialize).EndInit()
> Me.ResumeLayout(False)
> End Sub
> #End Region
> Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles btnUpdate.Click
> OdbcDataAdapter1.Update(DsTags1)
> MessageBox.Show("Database Updated!")
> End Sub
> Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnLoad.Click
> OdbcDataAdapter1.Fill(DsTags1)
> MessageBox.Show("Data Table Loaded Successfully!")
> End Sub
> End Class
>
> That's the long and short of it! Appreciate any help.
>
> *** Sent via Developersdex http://www.codecomments.com ***
> Don't just participate in USENET...get rewarded for it!

Error :Execute Trigger From Remote Server To another Server By Linked Server

i did "Linked server" between To Servers , and it's Working.

For Example :

Server 1 =S1.

Server = S2.

i create table in S1 : name = TblS1

i create same table in S2 : name TblS2

and i create trigger(name tr_cpD) From S1 in TblS1 For send data To TblS2 in S2

/****************** trigger Code ***************

CREATE TRIGGER dbo.tr_cpD

ON dbo.TblS1

AFTER INSERT

AS

BEGIN

SET NOCOUNT ON;

insert into [S2].[dbname].[dbo].[TblS2] Select ID,Name from inserted

END

**************************************************

result is :

Msg 7399, Level 16, State 1, Procedure tr_cpD, Line 14

The OLE DB provider "SQLNCLI" for linked server "S2" reported an error. The provider did not give any information about the error.

Msg 7312, Level 16, State 1, Procedure tr_cpD, Line 14

Invalid use of schema or catalog for OLE DB provider "SQLNCLI" for linked server "S2". A four-part name was supplied, but the provider does not expose the necessary interfaces to use a catalog or schema.

how i can execute this trigger

Just to clarify: does the insert statement work outside of the trigger from the same S1 server?|||

Yes.

it's Work from Stored Procduers without TRAN (Transaction) .

if i use Transaction From Stored Procduers is not work.

Give me same result above.

|||Is MSDTC enabled on both servers? I think insert from the trigger into a linked server is done inside the distributed transaction.
But I would expect some transaction specific error if it was not so.|||

Microsoft proived some solution, how to overcome this problem. Try it.

http://support.microsoft.com/kb/873160

I tried in the LAN its working fine. But, still in the WAN is not working.

Error :Execute Trigger From Remote Server To another Server By Linked Server

i did "Linked server" between To Servers , and it's Working.

For Example :

Server 1 =S1.

Server = S2.

i create table in S1 : name = TblS1

i create same table in S2 : name TblS2

and i create trigger(name tr_cpD) From S1 in TblS1 For send data To TblS2 in S2

/****************** trigger Code ***************

CREATE TRIGGER dbo.tr_cpD

ON dbo.TblS1

AFTER INSERT

AS

BEGIN

SET NOCOUNT ON;

insert into [S2].[dbname].[dbo].[TblS2] Select ID,Name from inserted

END

**************************************************

result is :

Msg 7399, Level 16, State 1, Procedure tr_cpD, Line 14

The OLE DB provider "SQLNCLI" for linked server "S2" reported an error. The provider did not give any information about the error.

Msg 7312, Level 16, State 1, Procedure tr_cpD, Line 14

Invalid use of schema or catalog for OLE DB provider "SQLNCLI" for linked server "S2". A four-part name was supplied, but the provider does not expose the necessary interfaces to use a catalog or schema.

how i can execute this trigger

Just to clarify: does the insert statement work outside of the trigger from the same S1 server?|||

Yes.

it's Work from Stored Procduers without TRAN (Transaction) .

if i use Transaction From Stored Procduers is not work.

Give me same result above.

|||Is MSDTC enabled on both servers? I think insert from the trigger into a linked server is done inside the distributed transaction.
But I would expect some transaction specific error if it was not so.|||

Microsoft proived some solution, how to overcome this problem. Try it.

http://support.microsoft.com/kb/873160

I tried in the LAN its working fine. But, still in the WAN is not working.

Sunday, February 26, 2012

error : Only constants, constant expressions, or variables allowed here.

hi all,
when I try to do the following insert for the table test

create table test (outputs character(10), chk integer)

insert into test values('a',((select count(*) from test where outputs='a')+1))

I am getting the error
The name 'outputs' is illegal in this context. Only constants, constant expressions, or variables allowed here. Column names are illegal.

when i tried the same in DB2 it's working fine. is there anyerror in my syntax or this kind of function not allowed in SQL Server.

regards
MelbUse a SELECT instead of the VALUES clause.

-PatP

Error : Cannot open user default database. Login failed.

I work with Microsoft visual studio 2005.
i get data from a table by ADO.NET :

SqlConnection sqlConn = new SqlConnection(strConnectionString);
sqlConn.Open();
.....

it works fine.

but when i open the SQL Server 2005 express edition and connect to the server (inside the same computer) to check something and then get back to the VS and run the code again ,the Open() function fails with the exception :

{"Cannot open user default database. Login failed.\r\nLogin failed for user 'DOMAIN\\asaf_a'."


disconnecting the server doesn't help and even closing the SQL Server 2005 application doesn't help.
Only restarting the computer enables the Open() command to work again.

Why ?

Every user has a default database specified. If you are using a SQLConnectinstring you are normally redirecting the user within the connectionstring to a specific database (Initial Catalog). By connecting with another tool which does not have the availbility to choose a starting database the user is redirected to its "home" / default database. If the database was dropped in the meantime, or the user was denied access / or even not granted, the login procedure will fail. You can set the user defaults database with using the procedure sp_defaultdb or by using any gui which can administer the logins.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de|||

Thanks jens,

i solved the problem.

It was my connection string all along. it was wrong. This was the problem.

I changed the connection string from :

string strConnectionString = @."Server=.\SQLTESTING;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL.3\MSSQL\Data\TestDB.mdf;Integrated Security=SSPI";

To :

string strConnectionString = @."Server=.\SQLTESTING;Integrated Security=TRUE;Database=TestDB";

now i can use (Open) the TestDB Database from the VS code even when the SQL Server 2005 is also connected to this database.

Thanks!

Error (8626) while inserting record into table with text field and which is the base for i

I have a problem with inserting records into table when an indexed view
is based on it.
Table has text field (without it there is no problem, but I need it).
Here is a sample code:

USE test
GO

CREATE TABLE dbo.aTable (
[id] INT NOT NULL
, [text] TEXT NOT NULL
)
GO

CREATE VIEW dbo.aView
WITH SCHEMABINDING AS
SELECT [id]
, CAST([text] AS VARCHAR(8000)) [text]
FROM dbo.aTable
GO

CREATE TRIGGER dbo.aTrigger ON dbo.aView INSTEAD OF INSERT
AS
BEGIN
INSERT INTO aTable
SELECT [id], [text]
FROM inserted
END
GO

Do the insert into aTable (also through aView).

INSERT INTO dbo.aTable VALUES (1, 'a')
INSERT INTO dbo.aView VALUES (2, 'b')

Still do not have any problem. But when I need index on view

CREATE UNIQUE CLUSTERED INDEX [id] ON dbo.aView ([id])
GO

I get following error while inserting record into aTable:

-- Server: Msg 8626, Level 16, State 1, Procedure aTrigger, Line 4
-- Only text pointers are allowed in work tables, never text, ntext, or
image columns. The query processor produced a query plan that required
a text, ntext, or image column in a work table.

Does anyone know what causes the error?ing42 (Inga.Korczowska@.gmail.com) writes:
> Do the insert into aTable (also through aView).
> INSERT INTO dbo.aTable VALUES (1, 'a')
> INSERT INTO dbo.aView VALUES (2, 'b')
> Still do not have any problem. But when I need index on view
> CREATE UNIQUE CLUSTERED INDEX [id] ON dbo.aView ([id])
> GO
> I get following error while inserting record into aTable:
> -- Server: Msg 8626, Level 16, State 1, Procedure aTrigger, Line 4
> -- Only text pointers are allowed in work tables, never text, ntext, or
> image columns. The query processor produced a query plan that required
> a text, ntext, or image column in a work table.
> Does anyone know what causes the error?

Did you notice the warning when you created the index:

Warning: The optimizer cannot use the index because the select list of
the view contains a non-aggregate expression.

So the index is not of much use. I guess you have hit a restriction
in SQL Server, which does not report as such in a nice way. When I
run your code in SQL 2005, I get:

Msg 1942, Level 16, State 1, Line 1
Cannot create index on view 'tempdb.dbo.aView'. It contains text, ntext,
image or xml columns.

Which is a more resolute message.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Error (1552) ODBC, Insert Execute Error

Hi, I have a program called dbms/copy that I use to conver clarion database tables. The program first creates the table, if already exists I delete and recreate. This part works fine. When it tries to insert the records I get the following error message:

Error (1552)

ODBC, Insert Execute Error -> Buffer Contained 100 Records but only 0 Records were written

I created a System DSN ODBC link to the SQL Server. I tried using the "sa" user, as well as creating a user and checking off all available permissions. It seems to be a permissions problem to me, although it appears I have permission to do everything. It is definately able to connect since it has no problem creating/deleting/recreating the table in the SQL Server database.

I tried doing the same import with an ODBC connection to a Microsoft Access database and it works without any problems.

Any idea what's giving me this error?I turned on ODBC tracing and the following errors showed up in the SQL.log file:

dbmswin7 f58-b90 ENTER SQLSetStmtAttr
SQLHSTMT 00E51F98
SQLINTEGER 6 <SQL_ATTR_CURSOR_TYPE>
SQLPOINTER 0x00000001
SQLINTEGER 0

dbmswin7 f58-b90 EXIT SQLSetStmtAttr with return code -1 (SQL_ERROR)
SQLHSTMT 00E51F98
SQLINTEGER 6 <SQL_ATTR_CURSOR_TYPE>
SQLPOINTER 0x00000001
SQLINTEGER 0

DIAG [24000] [Microsoft][ODBC Driver Manager] Invalid cursor state (0)

dbmswin7 f58-b90 ENTER SQLSetStmtAttr
SQLHSTMT 00E51F98
SQLINTEGER 7 <SQL_ATTR_CONCURRENCY>
SQLPOINTER 0x00000003
SQLINTEGER 0

dbmswin7 f58-b90 EXIT SQLSetStmtAttr with return code -1 (SQL_ERROR)
SQLHSTMT 00E51F98
SQLINTEGER 7 <SQL_ATTR_CONCURRENCY>
SQLPOINTER 0x00000003
SQLINTEGER 0

DIAG [24000] [Microsoft][ODBC Driver Manager] Invalid cursor state (0)

dbmswin7 f58-b90 ENTER SQLSetStmtAttr
SQLHSTMT 00E51F98
SQLINTEGER 5 <SQL_ATTR_ROW_BIND_TYPE>
SQLPOINTER 0x00000000
SQLINTEGER 0

dbmswin7 f58-b90 EXIT SQLSetStmtAttr with return code 0 (SQL_SUCCESS)
SQLHSTMT 00E51F98
SQLINTEGER 5 <SQL_ATTR_ROW_BIND_TYPE>
SQLPOINTER 0x00000000
SQLINTEGER 0

dbmswin7 f58-b90 ENTER SQLSetStmtAttr
SQLHSTMT 00E51F98
SQLINTEGER 27 <SQL_ATTR_ROW_ARRAY_SIZE>
SQLPOINTER 0x00000064
SQLINTEGER 0

dbmswin7 f58-b90 EXIT SQLSetStmtAttr with return code 0 (SQL_SUCCESS)
SQLHSTMT 00E51F98
SQLINTEGER 27 <SQL_ATTR_ROW_ARRAY_SIZE>
SQLPOINTER 0x00000064 (BADMEM)
SQLINTEGER 0

dbmswin7 f58-b90 ENTER SQLBulkOperations
SQLHSTMT 00E51F98
SQLSMALLINT 4

dbmswin7 f58-b90 EXIT SQLBulkOperations with return code -1 (SQL_ERROR)
SQLHSTMT 00E51F98
SQLSMALLINT 4

DIAG [S1092] [Microsoft][ODBC SQL Server Driver]Invalid attribute/option identifier (0)

dbmswin7 f58-b90 ENTER SQLRowCount
HSTMT 00E51F98
SQLLEN * 0x0012F7F4

dbmswin7 f58-b90 EXIT SQLRowCount with return code 0 (SQL_SUCCESS)
HSTMT 00E51F98
SQLLEN * 0x0012F7F4 (0)

dbmswin7 f58-b90 ENTER SQLDisconnect
HDBC 00E515E8

dbmswin7 f58-b90 EXIT SQLDisconnect with return code 0 (SQL_SUCCESS)
HDBC 00E515E8

Originally posted by UltraSmooth
Hi, I have a program called dbms/copy that I use to conver clarion database tables. The program first creates the table, if already exists I delete and recreate. This part works fine. When it tries to insert the records I get the following error message:

Error (1552)

ODBC, Insert Execute Error -> Buffer Contained 100 Records but only 0 Records were written

I created a System DSN ODBC link to the SQL Server. I tried using the "sa" user, as well as creating a user and checking off all available permissions. It seems to be a permissions problem to me, although it appears I have permission to do everything. It is definately able to connect since it has no problem creating/deleting/recreating the table in the SQL Server database.

I tried doing the same import with an ODBC connection to a Microsoft Access database and it works without any problems.

Any idea what's giving me this error?

Friday, February 24, 2012

Error - updating tables row using SqlDataSource

I have such a problem:

i try to update a row in my table using:

protected void selectButton_Click(object sender, EventArgs e)
{
String taskID = projectsGridView.SelectedRow.Cells[0].Text;
usersSqlDataSource.UpdateCommand = "update [Users] set [TaskID]=@.task where [UserID]=1";
usersSqlDataSource.UpdateParameters.Add("task", taskID);
usersSqlDataSource.Update();
}

And i receive error on usersSqlDataSource.Update():

You have specified that your update command compares all values on SqlDataSource 'usersSqlDataSource', but the dictionary passed in for oldValues is empty

What have i done wrong? Parameter are not set?

Check ConflictDetection attribute in your DataSource declaration.

Based on your usage it should be

ConflictDetection="OverwriteChanges"

Refer to the following link to better understand the implications of this setting

http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.sqldatasource.conflictdetection.aspx

|||

One way to solve this is to change the ConflictDetection property of your datasource to OverWriteChanges. At the moment it is set at CompareAllValues. If you want to keep the CompareAllValues setting, you need to add the old Values for each parameter to the UpdateParameters collection too.http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.oldvaluesparameterformatstring(vs.80).aspx

|||

Yes, it works fine now, thanks!

Sunday, February 19, 2012

Error - subquery returning more than one value

Hie.

I have a trigger that monitors changes to my table fields but I get an error saying subquery returned more than one value.Below is the code for my trigger, hope you will figure out whats happening..

CREATE TRIGGER trgmyTableAuditFields ON myTable
WITH ENCRYPTION
FOR INSERT, UPDATE, DELETE
AS
BEGIN

DECLARE @.col VARCHAR(200)
DECLARE @.primarykeycol VARCHAR(200)
DECLARE @.sql VARCHAR(2000)
DECLARE @.action VARCHAR(200)
DECLARE @.AuditInsert BIT
DECLARE @.AuditUpdate BIT
DECLARE @.AuditDelete BIT

SELECT @.action =
CASE
WHEN (SELECT COUNT(*) FROM deleted) = 0 THEN 'INSERTION'
WHEN (SELECT COUNT(*) FROM inserted) = 0 THEN 'DELETION'
ELSE 'UPDATE'
END

DECLARE curAuditFields CURSOR FOR
SELECT c.[name], ac.[AuditInsert], ac.[AuditUpdate], ac.[AuditDelete]
FROM syscolumns c
INNER JOIN sysobjects o ON o.[id] = c.[id]
INNER JOIN aucAuditColumns ac ON ac.[Column] = c.[name] AND ac.[Table] = o.[name]
WHERE o.[name] = 'myTable'
AND c.[xtype] NOT IN (35, 99, 34)
OPEN curAuditFields

FETCH NEXT FROM curAuditFields INTO @.col, @.AuditInsert, @.AuditUpdate, @.AuditDelete

SELECT [EffectiveDate],[LowerThresholdAmount],[ThresholdAmount],[Percentage],[ID] INTO #new FROM inserted
SELECT [EffectiveDate],[LowerThresholdAmount],[ThresholdAmount],[Percentage],[ID] INTO #old FROM deleted

WHILE @.@.FETCH_STATUS = 0 BEGIN

IF (@.action = 'INSERTION' AND @.AuditInsert = 1) OR
(@.action = 'UPDATE' AND @.AuditUpdate = 1) OR
(@.action = 'DELETION' AND @.AuditDelete = 1)
BEGIN

SET @.sql = 'IF (SELECT [' + @.col + '] FROM #new) <> (SELECT [' + @.col + '] FROM #old) OR (SELECT COUNT(*) FROM #old) = 0 OR (SELECT COUNT(*) FROM #new) = 0 BEGIN' + CHAR(10) +
'DECLARE @.old VARCHAR(50)' + CHAR(10) +
'DECLARE @.new VARCHAR(50)' + CHAR(10) +
' DECLARE @.RecordVal VARCHAR(50)' + CHAR(10) +

' SELECT @.new = CAST([' + @.col + '] AS VARCHAR(50)) FROM #new' + CHAR(10) +
' SELECT @.old = CAST([' + @.col + '] AS VARCHAR(50)) FROM #old' + CHAR(10) +
' SELECT @.RecordVal = CAST([ID] AS VARCHAR(50)) FROM #old' + CHAR(10) +
'IF @.RecordVal IS NULL BEGIN' + CHAR(10) +
'SELECT @.RecordVal = CAST([ID] AS VARCHAR(50)) FROM #new' + CHAR(10) +
'END' + CHAR(10) +

'INSERT INTO AuditTable([Username], ModificationDate, SourceTable, ModifiedField, OldValue, NewValue, [Action], [RecordID])' + CHAR(10) +
'VALUES (''' + SUSER_SNAME(SUSER_SID()) + ''',''' + CAST(GETDATE() AS VARCHAR(20)) + ''', ''myTable'', ''' + @.col + ''', @.old, @.new, ''' + @.action + ''', @.RecordVal)' + CHAR(10) +
'END'
EXEC (@.sql)
END

FETCH NEXT FROM curAuditFields INTO @.col, @.AuditInsert, @.AuditUpdate, @.AuditDelete
END

DROP TABLE #new
DROP TABLE #old

CLOSE curAuditFields
DEALLOCATE curAuditFields
END

Quote:

Originally Posted by Aleck

Hie.

I have a trigger that monitors changes to my table fields but I get an error saying subquery returned more than one value.Below is the code for my trigger, hope you will figure out whats happening..

CREATE TRIGGER trgmyTableAuditFields ON myTable
WITH ENCRYPTION
FOR INSERT, UPDATE, DELETE
AS
BEGIN

DECLARE @.col VARCHAR(200)
DECLARE @.primarykeycol VARCHAR(200)
DECLARE @.sql VARCHAR(2000)
DECLARE @.action VARCHAR(200)
DECLARE @.AuditInsert BIT
DECLARE @.AuditUpdate BIT
DECLARE @.AuditDelete BIT

SELECT @.action =
CASE
WHEN (SELECT COUNT(*) FROM deleted) = 0 THEN 'INSERTION'
WHEN (SELECT COUNT(*) FROM inserted) = 0 THEN 'DELETION'
ELSE 'UPDATE'
END

DECLARE curAuditFields CURSOR FOR
SELECT c.[name], ac.[AuditInsert], ac.[AuditUpdate], ac.[AuditDelete]
FROM syscolumns c
INNER JOIN sysobjects o ON o.[id] = c.[id]
INNER JOIN aucAuditColumns ac ON ac.[Column] = c.[name] AND ac.[Table] = o.[name]
WHERE o.[name] = 'myTable'
AND c.[xtype] NOT IN (35, 99, 34)
OPEN curAuditFields

FETCH NEXT FROM curAuditFields INTO @.col, @.AuditInsert, @.AuditUpdate, @.AuditDelete

SELECT [EffectiveDate],[LowerThresholdAmount],[ThresholdAmount],[Percentage],[ID] INTO #new FROM inserted
SELECT [EffectiveDate],[LowerThresholdAmount],[ThresholdAmount],[Percentage],[ID] INTO #old FROM deleted

WHILE @.@.FETCH_STATUS = 0 BEGIN

IF (@.action = 'INSERTION' AND @.AuditInsert = 1) OR
(@.action = 'UPDATE' AND @.AuditUpdate = 1) OR
(@.action = 'DELETION' AND @.AuditDelete = 1)
BEGIN

SET @.sql = 'IF (SELECT [' + @.col + '] FROM #new) <> (SELECT [' + @.col + '] FROM #old) OR (SELECT COUNT(*) FROM #old) = 0 OR (SELECT COUNT(*) FROM #new) = 0 BEGIN' + CHAR(10) +
'DECLARE @.old VARCHAR(50)' + CHAR(10) +
'DECLARE @.new VARCHAR(50)' + CHAR(10) +
' DECLARE @.RecordVal VARCHAR(50)' + CHAR(10) +

' SELECT @.new = CAST([' + @.col + '] AS VARCHAR(50)) FROM #new' + CHAR(10) +
' SELECT @.old = CAST([' + @.col + '] AS VARCHAR(50)) FROM #old' + CHAR(10) +
' SELECT @.RecordVal = CAST([ID] AS VARCHAR(50)) FROM #old' + CHAR(10) +
'IF @.RecordVal IS NULL BEGIN' + CHAR(10) +
'SELECT @.RecordVal = CAST([ID] AS VARCHAR(50)) FROM #new' + CHAR(10) +
'END' + CHAR(10) +

'INSERT INTO AuditTable([Username], ModificationDate, SourceTable, ModifiedField, OldValue, NewValue, [Action], [RecordID])' + CHAR(10) +
'VALUES (''' + SUSER_SNAME(SUSER_SID()) + ''',''' + CAST(GETDATE() AS VARCHAR(20)) + ''', ''myTable'', ''' + @.col + ''', @.old, @.new, ''' + @.action + ''', @.RecordVal)' + CHAR(10) +
'END'
EXEC (@.sql)
END

FETCH NEXT FROM curAuditFields INTO @.col, @.AuditInsert, @.AuditUpdate, @.AuditDelete
END

DROP TABLE #new
DROP TABLE #old

CLOSE curAuditFields
DEALLOCATE curAuditFields
END


i did not continue reading your code...am not sure how efficient it is to put a CUSOR inside a trigger. maybe you would want to find another way of doing this