|
I've got a fairly simple bit of code which will call a stored proc with the following signature:
dbo.UpdateAssembler (@Id int, @Name char(20), @IsActive bit, @Stamp timestamp) I've created and initialized an SqlCommand object with the appropriate parameters setup, the relevant one in this case "Id" has it's IsNullable property set to true. When I try and execute the command I get the following exception:
Procedure or Function 'UpdateAssembler' expects parameter '@Id', which was not supplied. Hmm , I've set Id in the previous lines of code (which could be an int or null , the stored proc does something different if Id is null ).
Any ideas on what might be causing this exception, note that I have verified the following:
- A parameter by the name of 'Id' does exist in the command's parameters (C# side of things)
- Stored proc does want an Id parameter
- The stored proc works fine if I invoke it through the UI in either VS2005 or the Management Studio.
Sig cops got me...
|
|
|
|
|
Ed.Poore wrote: A parameter by the name of 'Id' does exist in the command's parameters (C# side of things)
Okay... But it is looking for a parameter called @Id . Do you supply that parameter?
You might want to post your code - It sounds like a really simple thing like a typo you just need a second pair of eyes to see.
|
|
|
|
|
Hmm, I seem to remember the last time I did something like this it didn't want the @ in the SqlParameter's name, but I shall check it, then I'll post the code if not successful since it's taking an age for VS to load.
Sig cops got me...
|
|
|
|
|
Ok here's the code (putting the @ in made no difference)
Stored Procedure:
ALTER PROCEDURE dbo.UpdateAssembler (@Id int, @Name char(20), @IsActive bit, @Stamp timestamp) AS
BEGIN
IF EXISTS(SELECT * FROM Assembler WHERE ID = @Id)
IF EXISTS(SELECT * FROM Assembler WHERE (ID = @Id AND Stamp = @Stamp))
UPDATE Assembler
SET Name = @Name,
IsActive = @IsActive
WHERE ID = @Id
ELSE
RAISERROR('Different TimeStamps',10,1)
ELSE
INSERT INTO Assembler
(Name, IsActive)
VALUES (@Name, @IsActive)
END Building the SqlCommand (in a semi-factory like method thingy-ma-bob):
SqlCommand command = new SqlCommand("UpdateAssembler");
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("Id", SqlDbType.Int);
command.Parameters.Add("Stamp", SqlDbType.Timestamp);
command.Parameters["Id"].IsNullable = true;
command.Parameters["Stamp"].IsNullable = true; Executing the command:
updateCommand.Parameters["Id"].Value = item.Id;
updateCommand.Parameters["Stamp"].Value = item.TimeStamp;
updateCommand.ExecuteNonQuery(); Note that certain irrelevant bits have been cut out.
Sig cops got me...
|
|
|
|
|
Could you do a check on item.Id and if it is null replace the value sent as the parameter to DBNull.Value ?
|
|
|
|
|
I think I tried that, but it was before I noticed a couple of other mistakes so when I get the chance in a couple of hours I shall do that.
Sig cops got me...
|
|
|
|
|
Yes that's cured it, thanks.
Sig cops got me...
|
|
|
|
|
Ed.Poore wrote: command.Parameters.Add("Id", SqlDbType.Int);
command.Parameters.Add("Stamp", SqlDbType.Timestamp);
command.Parameters["Id"].IsNullable = true;
command.Parameters["Stamp"].IsNullable = true;
If i'm not wrong the SqlParameters are prefixed with @ symbol, and the above lines should be like this:
command.Parameters.Add("@Id", SqlDbType.Int);
command.Parameters.Add("@Stamp", SqlDbType.Timestamp);
command.Parameters["@Id"].IsNullable = true;
command.Parameters["@Stamp"].IsNullable = true;
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
I've tried that and it doesn't seem to make any difference
Sig cops got me...
|
|
|
|
|
Please tell me how to fill null data in textbox or other form controls in VB.Net from Sql Server 2000. I found error in dataset on runtime the application.
Thanks
|
|
|
|
|
rehan_cop wrote: how to fill null data in textbox or other form controls in VB.Net
try following these steps.
1. check the retrieved data for null value, if it is Nothing then
2. set the textbox.Text to empty string or set the controls with suitable values.
rehan_cop wrote: I found error in dataset on runtime the application
what sort of error it is? its not clear.
AND
read this[^]
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
hello...
i am using crystal reports 9 to make a prescription of a patient from the patienttable and disease table.the disease table takes patient id as a foriegn key. now i have 2 problems:
1. i am unable to get patients name of the patient table using the foriegn key
2. how would i show multiple diseases with out getting the disease label printed time and again on the prescription page.
3. how would i use a view... if that is a better option.
thanx...
haseeb
|
|
|
|
|
I have a problem. Whenever we pass an insert statement against database table the exception can be cathced by using sqlexception parameter. I have done with exception where there is a problem with the primary key because i know the error code it genereates when there is a primary key error. But how can i do the same type of checking when there is an error related to foreign key. Wht is the error code for foreign key related errors. Something like below
try<br />
{<br />
insert into database;<br />
if (success)<br />
then do nothing;<br />
else<br />
check about the cause of exception<br />
}<br />
catch<br />
{<br />
if (primary key exception)<br />
dosomething;<br />
else if(foreign key exception)<br />
dosomething;<br />
else<br />
dosomething;<br />
}
any help will be wellcomed.
Any suggestion is well received. thanx in advance
|
|
|
|
|
If I have a problem like this I create a simple test application and experiment. I would create an INSERT that will cause a foreign key violation and see what it returns.
How did you find the value of the Primary Key error in the first place?
|
|
|
|
|
It should be telling you that bizdate isn't contained in an aggregate or in a GROUP BY clause. As soon as you roll up results in an aggregate function, everything in the SELECT list must be aggregated or one of the fields used to group.
You'll have to select the value separately, unless you want to show figures grouped for each distinct value in that column, in which case you should use GROUP BY . If you want the latest date/time that this occurred, you could use MAX(bizdate) instead.
|
|
|
|
|
I have create a SQL which calculate the daily sale but it will only show 1 day when i run it
<br />
<br />
select t1.supermarket,t1.softline, t1.hardline, (t1.supermarket+t1.softline+ t1.hardline)as TOTAL <br />
from (select (select sum(totalsales+returnamt)as TotalSoft from tot_item <br />
where bizdate='2006-10-1'and (deptcode= 11 or deptcode=12 or <br />
deptcode=13 or deptcode=14 or deptcode= 15 or deptcode= 16 or deptcode= 17 ))as softline,<br />
<br />
(select sum (totalsales+returnamt)as TotalHard from tot_item <br />
where bizdate='2006-10-1'and (deptcode= 21 or deptcode=22 or deptcode=23 or deptcode=<br />
24 or deptcode= 25 or deptcode=26 or deptcode= 27 or deptcode= 28 or deptcode= 29 ) )as hardline,<br />
<br />
(select sum(totalsales+returnamt)as TotalSupermarket from tot_item <br />
where bizdate='2006-10-1' and (deptcode= 30 or deptcode=40 or deptcode=50 or deptcode=<br />
60 or deptcode= 70 or deptcode=80 or deptcode= 90)) as supermarket <br />
)as t1 <br />
<br />
but i want to show like the daily result between day 1- day 15 so i create this SQL but the result not wat i expected, the RESULT should the TOTAL sum of this 15 days.... i want to show 1 by 1 for the daily sale... how?
select t1.supermarket,t1.softline, t1.hardline, (t1.supermarket+t1.softline+ t1.hardline)as TOTAL <br />
from (select (select sum(totalsales+returnamt)as sototal from tot_item <br />
where bizdate<='2006-10-15' and bizdate>='2006-10-01'and (deptcode= 11 or deptcode=12 or <br />
deptcode=13 or deptcode=14 or deptcode= 15 or deptcode= 16 or deptcode= 17 ))as softline,<br />
<br />
(select sum(totalsales+returnamt)as htotal from tot_item <br />
where bizdate<='2006-10-15' and bizdate>='2006-10-01'and (deptcode= 21 or deptcode=22 or deptcode=23 or deptcode=<br />
24 or deptcode= 25 or deptcode=26 or deptcode= 27 or deptcode= 28 or deptcode= 29 ) )as hardline,<br />
<br />
(select sum(totalsales+returnamt)as sutotal from tot_item <br />
where bizdate<='2006-10-15' and bizdate>='2006-10-01'and (deptcode= 30 or deptcode=40 or deptcode=50 or <br />
deptcode=60 or deptcode= 70 or deptcode=80 or deptcode= 90 )) as supermarket <br />
)as t1 <br />
|
|
|
|
|
Hmm...it's a bit hard to understand your query as it's too complicated.
You might want to simplify it a bit.
First, use IN instead of deptcode = 14 or deptcode = 15 and so on.
So let's format it first into:
SELECT t1.supermarket,t1.softline, t1.hardline, (t1.supermarket+t1.softline+ t1.hardline) AS TOTAL
FROM
(SELECT (SELECT SUM(totalsales+returnamt) AS TotalSoft
FROM tot_item
WHERE bizdate='2006-10-1' AND deptcode IN (11, 12, 13, 14, 15, 16, 17)) AS softline,
(SELECT SUM(totalsales+returnamt) AS TotalHard
FROM tot_item
WHEREbizdate='2006-10-1' AND deptcode IN (21, 22, 23, 24, 25, 26, 27, 28, 29)) AS hardline,
(SELECT sum(totalsales+returnamt) AS TotalSupermarket
FROM tot_item
WHERE bizdate='2006-10-1' AND deptcode IN (30, 40, 50, 60, 70, 80, 90)) AS supermarket
) AS t1
Now that it's more simplified, I found that you can actually separate softline, hardline, and supermarket into 3 separate queries to save the confusion, and we can use GROUP BY to show the sum for each bizdate.
Query1:
SELECT bizdate, SUM(totalsales+returnamt) AS TotalSoft
FROM tot_item
WHERE deptcode IN (11, 12, 13, 14, 15, 16, 17)
GROUP BY bizdate
Query2:
SELECT bizdate, SUM(totalsales+returnamt) AS TotalHard
FROM tot_item
WHERE deptcode IN (21, 22, 23, 24, 25, 26, 27, 28, 29) AS hardline
GROUP BY bizdate
Query3:
SELECT bizdate, sum(totalsales+returnamt) AS TotalSupermarket
FROM tot_item
WHERE deptcode IN (30, 40, 50, 60, 70, 80, 90) AS supermarket
GROUP BY bizdate
Now in your final query you can link all the total using the following:
SELECT Query1.bizdate, TotalSoft, TotalHard, TotalSupermarket
FROM Query1
LEFT JOIN Query2 ON Query1.bizdate = Query2.bizdate
LEFT JOIN Query3 ON Query1.bizdate = Query3.bizdate
This will return your daily result of the sale.
From there you can specify the 15 days total sum.
If you want to put them all as one big query, here's the query:
SELECT Query1.bizdate, TotalSoft, TotalHard, TotalSupermarket
FROM (SELECT bizdate, SUM(totalsales+returnamt) AS TotalSoft
FROM tot_item
WHERE deptcode IN (11, 12, 13, 14, 15, 16, 17)
GROUP BY bizdate) AS Query1
LEFT JOIN (SELECT bizdate, SUM(totalsales+returnamt) AS TotalHard
FROM tot_item
WHERE deptcode IN (21, 22, 23, 24, 25, 26, 27, 28, 29) AS hardline
GROUP BY bizdate) AS Query2
ON Query1.bizdate = Query2.bizdate
LEFT JOIN (SELECT bizdate, sum(totalsales+returnamt) AS TotalSupermarket
FROM tot_item
WHERE deptcode IN (30, 40, 50, 60, 70, 80, 90) AS supermarket
GROUP BY bizdate) AS Query3
ON Query1.bizdate = Query3.bizdate
I hope the explanation above helps in your problem.
Note: I'm blind coding, so please check the syntax for me, ok
Cheers,
Edbert
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
i got this error:
Server: Msg 156, Level 15, State 1, Line 8<br />
Incorrect syntax near the keyword 'AS'.<br />
Server: Msg 156, Level 15, State 1, Line 12<br />
Incorrect syntax near the keyword 'AS'.<br />
actaully where do i put the date that i want them to show on??
like
where bizdate<='2006-10-15' and bizdate>='2006-10-01 which it will show between '2006-10-01' and'2006-10-15'
|
|
|
|
|
Which query did you run? Does each query run?
You can put the WHERE condition at the end of the query, before the GROUP BY if there is any.
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
Oh. Scratch that. I forgot to delete the AS hardline and AS supermarket.
The code below should (hopefully) work
(Please delete the AS hardline and AS supermarket in Query2 and Query3 respectively)
SELECT Query1.bizdate, TotalSoft, TotalHard, TotalSupermarket
FROM (SELECT bizdate, SUM(totalsales+returnamt) AS TotalSoft
FROM tot_item
WHERE deptcode IN (11, 12, 13, 14, 15, 16, 17)
GROUP BY bizdate) AS Query1
LEFT JOIN (SELECT bizdate, SUM(totalsales+returnamt) AS TotalHard
FROM tot_item
WHERE deptcode IN (21, 22, 23, 24, 25, 26, 27, 28, 29)
GROUP BY bizdate) AS Query2
ON Query1.bizdate = Query2.bizdate
LEFT JOIN (SELECT bizdate, sum(totalsales+returnamt) AS TotalSupermarket
FROM tot_item
WHERE deptcode IN (30, 40, 50, 60, 70, 80, 90)
GROUP BY bizdate) AS Query3
ON Query1.bizdate = Query3.bizdate
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
yes is working!! Thank you so much ^.^v
|
|
|
|
|
please help me !!!?
I have a problem with sqlconnection definition
when I add the sqlconnection from toolbox :
like this:
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Private Sub InitializeComponent()
Me.sqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.sqlConnection1.ConnectionString = "Data Source=server;Initial Catalog=masterstd;User ID=sa"
Me.sqlConnection1.FireInfoMessageEventOnUserErrors = False
End Sub
Private WithEvents sqlConnection1 As System.Data.SqlClient.SqlConnection
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim cmduniversity As SqlCommand
Dim dtruniversity As SqlDataReader
cmduniversity = New SqlCommand("select * from university", sqlConnection1)
sqlConnection1.Open()
dtruniversity = cmduniversity.ExecuteReader
dtruniversity.Close()
sqlConnection1.Close()
End If
End Sub
End Class
in the sqlconnection.open the nullrefrence exception occures but
when i define myself this exception dosn't occure.
like this:
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Private Sub InitializeComponent()
End Sub
Private WithEvents sqlConnection1 As System.Data.SqlClient.SqlConnection
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
sqlConnection1 = New SqlConnection
sqlConnection1.ConnectionString = "Data Source=server;Initial Catalog=masterstd;User ID=sa"
sqlConnection1.FireInfoMessageEventOnUserErrors = False
Dim cmduniversity As SqlCommand
Dim dtruniversity As SqlDataReader
cmduniversity = New SqlCommand("select * from university", sqlConnection1)
sqlConnection1.Open()
dtruniversity = cmduniversity.ExecuteReader
dtruniversity.Close()
sqlConnection1.Close()
End If
End Sub
ava_h
|
|
|
|
|
This is the exact error I keep getting:
The Microsoft Jet database engine could not find the object 'MailingLabelsTemp'. Make sure the object exists and that you spell its name and the path name correctly. (The other tables for some reason get this error too, not just mailinglabelstemp)
The concept is at the beginning the program uses already existing tables in the db. These are temp tables. I tried deleting them and recreating them, but what kept happening is basically the same thing. When it tries to open the recordset the table doesn't exist.
So the program fills each of these temp tables (which have the same fields as in the datareports) and then ties the datareport to that datasource and voila. However, if I dont' clear the table every time I display the report again it includes all the data from the old report, in other words I must clear the table before I write to it. But for some reason, after I clear it this error keeps coming up.
But this error is preventing all of that from happening.
.. this is my code for doing that:
Public Function clearTable(ByVal tableName As String) As Boolean
On Error GoTo uhhuh
'myConnection.BeginTrans
'Debug.Print myConnection.state
myConnection.Execute "DELETE * FROM [" & tableName & "]" ' TRUNCATE TABLE [tableName]
'need to somehow delete the table's content here
'myConnection.CommitTrans
clearTable = True
Exit Function
uhhuh:
'Stop
myConnection.RollbackTrans
Err.Clear
End Function
These are all the places (3) where it comes up with the same error:
1)
Public Sub fillMailingTableFromRS()
clearTable cMailingTableName
myLabelsSet.Open "SELECT * FROM " & cMailingTableName, myConnection, adOpenStatic, adLockOptimistic, adCmdText
2)
Public Function clearTable(ByVal tableName As String) As Boolean
On Error GoTo uhhuh
'myConnection.BeginTrans
'Debug.Print myConnection.state
myConnection.Execute "DELETE * FROM [" & tableName & "]" ' TRUNCATE TABLE [tableName]
3)
myHomeSalesSet.Open "SELECT * FROM " & cHomeSalesTableName, myConnection, adOpenStatic, adLockOptimistic, adCmdText
Also these are other subs that may or may not make a difference..
Public Sub initMyDatabase()
initMyDBGlobals
'init the db
Dim strConnect As String, strQuery As String, cmd As String
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;"
strConnect = strConnect & "Persist Security Info=False;"
strConnect = strConnect & ";Data Source=" & myDBPath
myConnection.ConnectionString = strConnect
myConnection.ConnectionTimeout = 10
myConnection.CursorLocation = adOpenStatic
myConnection.Open
Public Sub closeMyDatabase()
On Error GoTo closeMyDBErr
Set myRecordSet = Nothing
Set myLabelsSet = Nothing
Set myHomeSalesSet = Nothing
clearTempTables
'close recordset first, then connection.
If myConnection.state = adStateOpen Then
myConnection.Close
End If
Set myConnection = Nothing
Set mydbobj = Nothing
Exit Sub
closeMyDBErr:
Resume Next
End Sub
Private Sub clearTempTables()
clearTable cMailingTableName
clearTable cHomeSalesTableName
'levels: myRecordSet, myrsSelection, myRSCriterion
'do not delete main table!
clearTable c2ndTable
clearTable c3rdTable
End Sub
|
|
|
|
|
My suggestion is instead of deleting and recreating temporary table, you can create a permanent table, and give it a PK (e.g. using GUID) that you can use for the particular function.
Then after you've finished with the data you can delete all records with the particular PK.
What was the error returned anyway? Oops. Saw the error message you posted.
Perhaps there are multiple users accessing the database and one user dropped the table while it is being used?
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
Actually, I did figure out what was going on. In a totally different portion of my program I was deleting and recreating the table right before the report creation. Then in my db mod file I was just trying to clear the table. Basically.. I messed up, and once I pulled out those lines the tables stopped vanishing on me.
|
|
|
|
|