Object Must Implement IConvertible Is A BUG Non Solved?
Aug 9, 2006
i try to do a simple insert using SQLDataSource and a Stored Procedure
I try all night and always have this error
Object Must Implement IConvertible
I can’t understand where I wrong..
Looking around I understand is maybe a typecasting problema but I not find nothing more understeable..
Could someone tell me why Microsoft release this SQLdatasorce making more difficult a simple insert?
If someone could help me to fix this problem please
Here is the code
------------------------------------------------------------------------------------------------------------
Protected
Sub btnSave_Click(
ByVal sender
As
Object,
ByVal e
As System.EventArgs)
Handles btnSave.Click
Try
SqlDataSource1.Insert()
Catch ex
As Exception
Response.Write(ex.ToString)
Finally
SqlDataSource1.Dispose()
End
Try
End Sub
------------------------------------------------------------------------------------------------------------
<
asp
:
SqlDataSource
ID
="SqlDataSource1"
runat
="server"
ConnectionString
="
<%$ ConnectionStrings:CommerceTemplate
%>
"
InsertCommandType
="StoredProcedure"
InsertCommand
="dbo.StoredProcedure1">
<
InsertParameters
>
<
asp
:
ControlParameter
ControlID
="DropDownListCategory"
Name
="@CategoryID"
PropertyName
="SelectedValue"
Type
="Int32"
/>
<
asp
:
ControlParameter
ControlID
="DropDownListCategory"
Name
="@ModelNumber"
PropertyName
="SelectedValue"
Type
="String"
/>
<
asp
:
ControlParameter
ControlID
="txtModelName"
Name
="@ModelName"
PropertyName
="Text"
Type
="String"
/>
<
asp
:
ControlParameter
ControlID
="txtProductImage"
Name
="@ProductImage"
PropertyName
="Text"
Type
="String"
/>
<
asp
:
ControlParameter
ControlID
="txtUnitCost"
Name
="@UnitCost"
PropertyName
="Text"
Type
="Decimal"
/>
<
asp
:
ControlParameter
ControlID
="txtDescription"
Name
="@Description"
PropertyName
="Text"
Type
="String"
/>
<
asp
:
ControlParameter
ControlID
="txtWeight"
Name
="@Weight"
PropertyName
="Text"
Type
="Decimal"
/>
<
asp
:
ControlParameter
ControlID
="txtDiscount"
Name
="@Discount"
PropertyName
="Text"
Type
="Decimal"
/>
<
asp
:
ControlParameter
ControlID
="chkIsActive"
Name
="@isActive"
PropertyName
="Checked"
Type
="Boolean"
/>
<
asp
:
ControlParameter
ControlID
="DropDownListAuthors"
Name
="@IDAuthor"
PropertyName
="SelectedItem"
Type
="Int32"
/>
</
InsertParameters
>
</
asp
:
SqlDataSource
>
------------------------------------------------------------------------------------------------------------
ALTER PROCEDURE
dbo.StoredProcedure1
@CategoryID
int,
@ModelNumber
nvarchar(50),
@ModelName
nvarchar(50),
@ProductImage
nvarchar(50),
@UnitCost
money,
@Description
varchar(500),
@weight
money,
@IsActive
bit,
@DiscountPerCent
int,
@IDAuthor
int
AS
INSERT INTO
dbo.CMRC_Products (
CategoryID,
ModelNumber,
ModelName,
ProductImage,
UnitCost,
Description,
weight,
IsActive,
DiscountPerCent,
IDAuthor
)
VALUES
(
@CategoryID,
@ModelNumber,
@ModelName,
@ProductImage,
@UnitCost,
@Description,
@weight,
@IsActive,
@DiscountPerCent,
@IDAuthor
)
SELECT
@@IDENTITY
as [NewID]
------------
View 4 Replies
ADVERTISEMENT
Feb 8, 2006
using (SqlConnection oConn = new SqlConnection(sConnection))
using (SqlCommand oCommand =
this.CreateSqlCommand("rcsp_employee_f_changerole.xml", oConn))
{
try { oConn.Open(); }
catch(Exception ex)
{
p_nErrorCode =
10;
p_sErrorMessage = "Error opening database connection during
RCEmployee.DBUpdate: " + ex.Message;
goto Failed;
}
oCommand.Parameters["@employeeid"].Value = p_gID;
oCommand.Parameters["@authorityid"].Value = p_gAuthorityID;
oCommand.Parameters["@role"].Value=sNewRole;
if (!ProcessNonQuery(oCommand,
sMethodName)) goto Failed;
Failed:
if (ErrorCode > 0) bReturn =
false;
oConn.Close();
}
}
return bReturn;
p_gID, p_gAuthorityID is of type guid.
sNewRole is of type string.
I get the error " Object must implement IConvertible at
oCommand.ExecuteNonQuery(); whihch is in the function if (!ProcessNonQuery(oCommand, sMethodName))
View 1 Replies
View Related
Oct 16, 2006
Using: VB.Net 2003, SQL Server 2000 and nText Column...
Examples: "Writing BLOB Values to a Database [Visual Basic]" and "Conserving Resources When Writing BLOB Values to SQL Server [Visual Basic]"
I modified the following code from the samples that were available in Help and MSDN. When my application reaches the ExecuteNonQuery statement it informs me that the Byte Array oDocument must implement IConvertible. I have even tried the extended version which uses a SQL Insert followed by UPDATETEXT with Pointers, and I get the same result with the Byte Array used in that example. My goal is to have Users Append certain documents to Proposals within my database, as I understand that is what I would be doing anyway if I used SharePoint.
Following the examples I have not trouble whatsoever reading an Image File from SQL Server 2000, and therefore I expect no trouble with nText Fields. I just cannot seem to insert Documents or Images via VB Code.
What is wrong with the examples that I cannot use the same code?
---- VB Code Follows ----
Private Sub btnSelectFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFile.Click
Dim oSQLConnection As System.Data.SqlClient.SqlConnection
Dim oSQLCommand As System.Data.SqlClient.SqlCommand
Dim oSQLDataReader As System.Data.SqlClient.SqlDataReader
Dim oDocument() As Byte
Try
'Define the Initial Directory to be the "My Documents" Directory.
ofdAttachment.InitialDirectory = "My Documents"
'Filter for File of Word, PDF, and Text. This will suffice for now.
ofdAttachment.Filter = "Word Documents (*.doc)|*.doc|PDFs (*.pdf)|*.pdf|Text Files (*.txt)|*.txt"
'Show the Dialog to Open a File.
ofdAttachment.ShowDialog()
'If the User Selected a File then attempt to Add the Attachment.
If ofdAttachment.FileName <> String.Empty Then
'Read the Document into a Byte Array.
oDocument = GetDocumentInBytes(ofdAttachment.FileName)
'Define the Connection to the SQL Database.
oSQLConnection = New System.Data.SqlClient.SqlConnection("Persist Security Info=False;Integrated Security=SSPI;database=proposal_tracking;server=dbserverdbserver;")
'Attempt to Open the SQL Connection.
oSQLConnection.Open()
'Create a New SQL Command Object.
oSQLCommand = New System.Data.SqlClient.SqlCommand
'Assign the SQL Connection information to the SQL Command Object.
oSQLCommand.Connection = oSQLConnection
'Define the SQL Statement to Attach the Document.
oSQLCommand.CommandText = "INSERT INTO Documents (DocumentName, Document) VALUES (@DocumentName, @Document)"
oSQLCommand.CommandType = CommandType.Text
'Define the Parameters of the SQL Statement.
oSQLCommand.Parameters.Add("@DocumentName", SqlDbType.VarChar).Value = Mid(ofdAttachment.FileName, ofdAttachment.FileName.LastIndexOf("") + 2)
oSQLCommand.Parameters.Add("@Document", SqlDbType.NText, oDocument.Length).Value = oDocument
'Execut the SQL Statement. Resulting in an Error that states:
'Object must implement IConvertible.
oSQLCommand.ExecuteNonQuery()
If Not oSQLCommand Is Nothing Then
oSQLCommand.Dispose()
oSQLCommand = Nothing
End If
If Not oSQLConnection Is Nothing Then
oSQLConnection.Close()
oSQLConnection = Nothing
End If
End If
Catch sqlex As System.Data.SqlClient.SqlException
MsgBox(sqlex.Message)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Public Shared Function GetDocumentInBytes(ByVal strFilePath As String) As Byte()
Dim ofsDocumentReader As System.IO.FileStream = New System.IO.FileStream(strFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim obrDocumentReader As System.IO.BinaryReader = New System.IO.BinaryReader(ofsDocumentReader)
Dim oDocument() As Byte
Try
oDocument = obrDocumentReader.ReadBytes(CInt(ofsDocumentReader.Length))
obrDocumentReader.Close()
ofsDocumentReader.Close()
Return oDocument
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
View 1 Replies
View Related
Apr 6, 2008
still having problems... here is my code.. (NOTE: I have no code in my .aspx.cs ...maybe that is my problem)
<%@ Page Language="C#" MasterPageFile="~/Admin/MasterPage2.master" AutoEventWireup="true" CodeFile="dUsers.aspx.cs" Inherits="Admin_dUsers" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" DataSourceID="SqlDataSource1" DataKeyNames="UserId" AutoGenerateDeleteButton="True" >
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
SelectCommand="SELECT UserId, First, Last, Email, CreateDate, LastLoginDate, IsApproved, IsLockedOut FROM aspnet_Membership"
DeleteCommand="DELETE FROM aspnet_Membership WHERE [UserId] = @UserId"
ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" >
<DeleteParameters>
<asp:Parameter Name="UserId" Type="Int32"/>
</DeleteParameters>
</asp:SqlDataSource>
</asp:Content>
-------------------------------------------------------------
when i click the delete button... this error appears..
-------------------------------------------------------------
Server Error in '/mapuaResearch' Application.
Object must implement IConvertible.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Object must implement IConvertible.Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[InvalidCastException: Object must implement IConvertible.]
System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +2514354
System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +257
System.Web.UI.WebControls.SqlDataSourceView.AddParameters(DbCommand command, ParameterCollection reference, IDictionary parameters, IDictionary exclusionList, String oldValuesParameterFormatString) +657
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDelete(IDictionary keys, IDictionary oldValues) +529
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +176
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +912
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +1067
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +215
System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +244
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3839
* i think i hav to have a code in my c# side.. but i have no idea how to do it.. can someone please help me!!! i really need it.. tnx a lot...
View 1 Replies
View Related
Dec 6, 2003
Hi,
I am trying to call a stored procedure to insert into my database. After I called Open(), it crashed on ExecuteNonQuery(). I get the following message.
Object must implement IConvertible.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Object must implement IConvertible.
Source Error:
Line 160:Try
Line 161:myConnection.Open()
Line 162:myCommand.ExecuteNonQuery()
Line 163:myConnection.Close()
What does this mean? If anyone encountered this error before, please let me know how to trace the error and fix it.
Thanks Gurus,
John
View 4 Replies
View Related
Dec 1, 2005
I've been playing around with the new data controls (DetailsView,FormView) and have been having problems when attempting to update a record that has a uniqueidentifier as its primary key.I get the error message:
Object must implement IConvertible. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Object must implement IConvertible.I gather this is because there is a bug that has propagated from the beta version.One suggested work around is from http://64.233.183.104/search?q=cache:GDjA62POtgcJ:scottonwriting.net/sowBlog/archive/11162005.aspx+Implicit+conversion+from+data+type+sql_variant+to+uniqueidentifier+is+not+allowed.+Use+the+CONVERT+function+to+run+this+query.&hl=en
The crux of the problem, it appears, is that the <asp:Parameter> value for the uniqueidentifier field is, by default, set to Type=�Object�. To fix this, simply remove the Type property altogether. That is, change the SqlDataSource parameter setting from something like:
<asp:SqlDataSource ...> <InsertParameters> <asp:Parameter Name=�UserId� Type=�Object� /> ... </InsertParameters></asp:SqlDataSource>
to:
<asp:SqlDataSource ...> <InsertParameters> <asp:Parameter Name=�UserId� /> ... </InsertParameters></asp:SqlDataSource>
This change worked for me; once the Type was removed the exception ceased and the updates/inserts worked as expected.Unfortunately this only partially worked for me as while it is fine for deletes it won't work for updates.If anyone can help shed any light on this I would greatly appreciate it.CheersMark
View 28 Replies
View Related
Jan 4, 2007
Hi, I am a beginner in ASP.NET 2.0
I am creating a simple blog website.
I am using a DataReader object to collect all of the entries in the database (in one full sweep) and then display them by adding rows to a table and populating them.
I would like to enable paging so that only 5 blog entries at a time are displayed. The user should be able to page backwards and forwards 5 at a time.
Please can somebody give me some ideas of how I should do this?
Should I read all of the data into some kind of list so that all of the data is then readily available? An arraylist or something?
I realise that the DataReader object reads in one continuous stream so I couldn't expect it to read backwards and forwards from the database.
I include a portion of my code below which reads the database.
Many thanks.
Dim objCommand As New SqlCommand objCommand.Connection = objConnection objConnection.Open() objCommand.CommandText = "SELECT BlogID, Date, Blog FROM BlogSite2_Blogs ORDER BY Date DESC"
Dim objReader As SqlDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
Dim dateDateTime As Date Dim strBlogEntry As String Dim intBlogID As Integer
Do While objReader.Read() intBlogID = objReader.GetValue(0) dateDateTime = objReader.GetDateTime(1) strBlogEntry = objReader.GetString(2)
CreateBlogRow(intBlogID, dateDateTime, strBlogEntry) Loop
objReader.Close()
View 3 Replies
View Related
Dec 28, 2007
Hi Guyz
it is taken from SQL2K5 SP2 readme.txt. Anyone have idea what to do to implement this ?
Our sp2 is failing. we suspect the above problem and researching it.we are running on default instance of SQL2K5 on win2003 ent sp2
"When you apply SP2, Setup upgrades system databases. If you have implemented restrictions on the ALTER DATABASE syntax, this upgrade may fail. Restrictions to ALTER DATABASE may include the following:
Explicitly denying the ALTER DATABASE statement.
A data definition language (DDL) trigger on ALTER DATABASE that rolls back the transaction containing the ALTER DATABASE statement.
If you have restrictions on ALTER DATABASE, and Setup fails to upgrade system databases to SP2, you must disable these restrictions and then re-run Setup."
thanks in advance.
View 4 Replies
View Related
Sep 20, 2006
Hi,
Now it´s working fine!!!!
On the Firewall of the Server, I´ve added the default port 1433 on the exceptions.
thanx!!!!
View 1 Replies
View Related
Feb 21, 2008
The problem is solved but still I would like to know what is going on behind the scenes. I was always thinking that the native client was involved and not oledb.
Using the Export/Import wizard you still end up going via SQL Server Agent that's where the Credential/Proxy items show up.
View 3 Replies
View Related
Jun 24, 2006
Upper case sentece in normal case sentence
View 6 Replies
View Related
Feb 25, 2003
I'm just beginning to use DTS. I have a test table which has only two column, char (10) and decimal (5,0). I want to do a simple transformation by adding the second column by 100 with the following statement, but I receive a type mismatch error!
Function Main()
DTSDestination("a")=DTSSource("a")
DTSDestination("b")=DTSSource("b").Value + 100
Main = DTSTransformStat_OK
End Function
or
Function Main()
dim x
DTSDestination("a")=DTSSource("a")
x = DTSSource("b").Value + 100
DTSDestination("b").Value = x
Main = DTSTransformStat_OK
End Function
View 2 Replies
View Related
Dec 8, 1999
Hello friends I need a very ergent help!!!!!!!!!!!!!
Problem: my sql server on production had everything grayed out, when I want to administer this server as a SA. eg: I can't add users, I can't backup and so on.
but the database is still running and users are accessing it.
This SQL database is accessed by an application(it can also create users on
the backend). I don't know how it happend ( i cant even get to errorlog).
I beleive somehow sa user rights were taken away from him. Can anyone tell me how to restore sa with all rights.
Please help me on this matter, because I have to do lots of important tasks on this server.
I appreciate all of your help.
Thanks
Ragul
View 2 Replies
View Related
Mar 12, 2008
Hi, hope someone can help. I have two tables
Test1 that lists all the training courses that i can count to find out the total as below.
select count (distinct Training_Course) as total
from Test1
Then Test2 lists all our customers and courses they have attended. I count the courses attended and then group by their ID.
select Cust_id, count (Attended) as TotalAttend
from Test2
Group by Cust_id
What i am now trying to do, without any luck, is find out which Customers have attended all training sessions by comparing the two queries and only bringing back the cust_id where it matches the total count from the Test1 query.
Make any sense? Any help/suggestions gratefully recieved.
View 4 Replies
View Related
Mar 23, 2008
Hello,uery - I'm Stuck
I'm very rusty with my SQL, and could use a little assistance on building this query. Thanks for taking the time to help me. It should be a relatively simple Count() query but I'm not getting the right results for some reason and I'm hoping somebody can point out my error to me.
I'm attempting to count the number of times each m_id is returned after running this query:
SELECT m_id
FROM taglink
WHERE m_id <> '25'
AND t_id
IN (
SELECT t_id
FROM taglink
WHERE m_id = '25'
)
which returns:
m_id
33
34
34
35
35
35
36
I want to count the number of times that m_id is returned so that the results of my query will be:
m_id | count
33 | 1
34 | 2
35 | 3
36 | 1
In my attempt to do this, I run the following query:
SELECT m_id, count( m_id ) AS "count"
FROM taglink
WHERE m_id
IN (
SELECT m_id
FROM taglink
WHERE m_id <> '25'
AND t_id
IN (
SELECT t_id
FROM taglink
WHERE m_id = '25'
)
)
GROUP BY m_id
The problem I'm having is that the query returns:
m_id | count
33 | 3
34 | 2
35 | 3
36 | 3
It seems to return the count of "3" for fields that should count "1," but count correctly if the fields count "2" or "3."
Perhaps somebody can spot my error... I can't seem to wrap my brain around this one. Thanks so much for your time!
View 4 Replies
View Related
Aug 9, 1999
i have a table "employee" , i have given grant all rights to a user
in sql 6.5 server . still whenever he tries to access the table from VB he gets an error "execute permission denied on table employee, owner dbo"
. if i log in the server with this user name and his password i am able to interact with the table . please help.
View 1 Replies
View Related
May 11, 2006
We've tried attaching the mdf files given to us by some customers using the script they've provided, too.
I created the database with the corresponding names, and tried to run their script. However, I get the message "The media family on device 'D:DatabaseDVVAD01.mdf' is incorrectly formed. SQL Server cannot process this media family."
What could possibly have gone wrong? Is it also possible that the file was not properly detached, or what?
View 1 Replies
View Related
May 14, 2008
I am re-writing a old query that update's it's value based on values at run time. Is there anyway to accomplish the following query where column s1.AI referances the values that were updated during run-time.
I want to avoid a Loop (i.e. cursor or a CTE).
Please help!
Declare @Stage Table(StartDate datetime,BenefitInterestID INT PRIMARY KEY, Amount MONEY, InterestAmount MONEY, Interest DECIMAL(10, 4), ai DECIMAL(10, 4))
Insert Into @Stage
Select
convert(datetime,'2006-12-01 00:00:00.000',101) as StartDate,1 as BenefitInterestID,1701.00 as amount,79.605 as InterestAmount ,0.1000 as Interest,0.0000 as ai
Union all
select '2007-12-01 00:00:00.000',2,172.80,7.92,0.0500,0
Union all
select '2008-12-01 00:00:00.000',4,0.00,0.00,0.0700,0
UPDATEs1
SETs1.ai = s1.Interest * coalesce((SELECT SUM(coalesce(s2.Amount,0) + coalesce(s2.InterestAmount,0)+coalesce(s2.ai,0)) FROM @Stage AS s2 WHERE s2.StartDate < s1.StartDate ),0)
FROM@Stage AS s1
select * from @Stage
My desired Results are
2006-12-01 00:00:00.00011701.0079.6050.10000.0000
2007-12-01 00:00:00.0002172.807.920.050089.0303
2008-12-01 00:00:00.00040.000.000.0700143.5300
But I am geting
2006-12-01 00:00:00.00011701.0079.6050.10000.0000
2007-12-01 00:00:00.0002172.807.920.050089.0303
2008-12-01 00:00:00.00040.000.000.0700137.2928
Due to as you can see on row 3 that the amount does not factor in the previous Years ai column when I sum, due to the update takes place at runtime.
Please help!
View 15 Replies
View Related
May 28, 2008
First, I'm not sure what format to post the SQL query in, but I'm using it in the Pawn programming language, so it's all on one line. Sorry if it's hard to read :(
Ok, I am supplying you guys with my database that I am having problems with. Basically, I'm telling it to ORDER BY ASC but it's not ordering it correctly. It's almost correct, but not perfect. I'm not sure if SQLite is much different than SQL standard, that's why I differentiate.
Here is the SQLite database:
*deleted*
The problem comes in when you execute this query:
SELECT p.alias, min(s.fin_time), s.cps, s.gcs, s.boosts, s.wpns, s.score, s.score_id FROM climb_scores s JOIN climb_players p ON s.user_id = p.user_id JOIN (SELECT user_id, fin_time, score_id FROM climb_scores WHERE map_name="j2s_4floors" AND cps = 0) g ON g.score_id=s.score_id GROUP BY s.user_id ORDER BY s.fin_time ASC LIMIT 20
The end goal is to have fin_time sorted in ascending order, but it's not working right. Can someone clue me in to the problem?
thanks!
View 1 Replies
View Related
May 30, 2008
hi guys, im having a sql problem for reporting here. here is the table
CREATE TABLE `tblasset` (
`AssetID` int(11) NOT NULL,
`AssetName` varchar(50) NOT NULL,
PRIMARY KEY (`AssetID`)
);
INSERT INTO `tblasset` (`AssetID`, `AssetName`) VALUES
(1, 'IPOD'),
(2, 'Laptop'),
(3, 'Sony PS3'),
(4, 'Wooden Cupboard'),
(5, 'Fridge');
CREATE TABLE `tblassetplacement` (
`PlacementID` int(11) NOT NULL,
`LocationID` int(11) NOT NULL,
`AssetID` int(11) NOT NULL,
`PlacementDate` bigint(20) NOT NULL,
`OfficerInChargeID` varchar(50) DEFAULT NULL,
PRIMARY KEY (`PlacementID`)
);
INSERT INTO `tblassetplacement` (`PlacementID`, `LocationID`, `AssetID`, `PlacementDate`, `OfficerInChargeID`) VALUES
(1, 3, 1, 1209628156, 'John'),
(2, 6, 1, 1209800956, 'Susan'),
(3, 3, 3, 1209714556, 'Erik'),
(4, 4, 3, 1210405756, 'Albert'),
(5, 5, 3, 1211096956, 'Fred');
CREATE TABLE `tbllocation` (
`LocationID` int(11) NOT NULL,
`LocationName` varchar(50) NOT NULL,
`ParentID` int(11) DEFAULT NULL,
PRIMARY KEY (`LocationID`),
KEY `ParentID` (`ParentID`)
);
INSERT INTO `tbllocation` (`LocationID`, `LocationName`, `ParentID`) VALUES
(1, 'Building A', NULL),
(2, 'Building B', NULL),
(3, 'Room 1', 1),
(4, 'Room 2', 1),
(5, 'Partition 1', 4),
(6, 'Room 1', 2);
basically the location looks like this
Location Tree View
---
.___ Building A
. .___ Room 1
. .___ Room 2
. .___ Partition 1
.
.___ Building B
. .___ Room 1
on tblAssetPlacement, the column PlacementDate is a unix timestamp stored as bigint.
the higher of its value means it is the latest placement.
so i had created a sql to pull the data like this:
SELECT
tblasset.AssetName,
tblassetplacement.OfficerInChargeID,
tblassetplacement.Locationid,
tbllocation.LocationName
FROM
tblasset,tblassetplacement, tbllocation,
(select tblassetplacement.AssetID,tblassetplacement.LocationID,MAX(tblassetplacement.PlacementDate) AS LatestDate from tblassetplacement group by tblassetplacement.AssetID) temptbl
where
tblasset.AssetID = tblassetplacement.AssetID
and tblassetplacement.PlacementDate = temptbl.LatestDate
and tblassetplacement.AssetID = temptbl.AssetID
and tbllocation.LocationID=tblassetplacement.LocationID
;
this will output:
---
AssetNameOfficerInChargeIDLocationIDLocationName
IPODSusan6Room 1
Sony PS3Fred5Partition 1
i would need to have a column ParentLocationName that directly shows the name of the parent's location as below:
---
AssetNameOfficerInChargeIDLocationIDLocationNameParentLocationName
IPODSusan6Room 1Building B
Sony PS3Fred5Partition 1Building A
is there a way to pull the parent's location name in one sql syntax?
View 4 Replies
View Related
Sep 14, 2006
Is there a way to supress output on one column in a SP, using data from the same row?
Like This:
SELECT Last, First, DOP, dbo.fnDueDate(DOP, 3, GETDATE()) AS NextQDue, dbo.fnDueDate(DOP, 6, GETDATE()) AS NextNSPDue, DATEADD(m, 1, DOP)AS InitialNSPDue, DATEADD(m, 1, DOP) AS InitialAssessDue, DOT, DisReason, DATEADD(m, 1, DOT) AS DisSummDue, Facility, Active
FROM dbo.tblResidents
But which returns null for some of the columns if DOT is not null?
DOT is the Termination Date, so the only columns that have any meaning once there is data in the DOT column are DisReason and DisSummDue. Also, if DOT *is* null, then the above columns also have no meaning.
I tried several variations of the following, but I can't figure it out
CREATE PROCEDURE [dbo].[spTesting] AS
BEGIN
SELECT Last, First, DOP, dbo.fnDueDate(DOP, 3, GETDATE()) AS NextQDue, dbo.fnDueDate(DOP, 6, GETDATE()) AS NextNSPDue, DATEADD(m, 1, DOP) AS InitialNSPDue, DATEADD(m, 1, DOP) AS InitialAssessDue, Facility
FROM dbo.tblResidents A
WHERE DOT IS NULL
UNION
SELECT Last, First, DOP, DOT, DisReason, DATEADD(m, 1, DOT) AS DisSummDue, Facility
FROM dbo.tblResidents I
END
GO
----------------
-Stephen
View 4 Replies
View Related
Jan 8, 2007
Hi,
I have an interesting problem here. I am running SQL Server 2005 and have a large database. After running some scalability tests over the weekend my MDF file size went up to 25GB and LDF file size went up to 27GB filling up all available disk space. I didn't do any backups, so it is understandable why the LDF file size is so large.
Now I am trying to shrink the LDF file. However, DBCC LOGINFO indicated that all LVFs within the LDF are active (Status = 2). I detached the database to make sure no active connections exist and ran CHECKPOINT, but still DBCC LOGINFO lists all LVFs with status 2. Since all LVFs are up to date I can't shrink my LDF file.
Why are all LVFs still active after detach/attach and checkpoint?
How can I shrink the LDF file?
Thanks.
Alec
View 1 Replies
View Related
Jan 8, 2008
Hello everybody,
I have a database, where all tables and stored procedures look like this:
dbo.table
dbo.sp
Is this naming because of the db owner creating the tables and stored procedures?
The db runs correctly in my asp.net aplication when i use a user that is db owner, but i want it to run with a 'normal' user that is in public role and has all rights except db_owner...
How can i solve my problem!
Using the user without db_owner rights brings in my application the error:
The EXECUTE permission was denied on the object 'myStoredProcedure', database 'myDatabase', schema 'dbo'.
Thanks for help!!!!
Steven****
--------------------------------------
Solution:
I have to give the User without DB_Owner Rights the schema permissions for dbo objects! This only works in sql server 2005!
View 1 Replies
View Related
Jul 23, 2005
Hello,We have an ADO.NET application using .NET version 1.1.4322 SP1. It iscalling stored procedures in a database that it never written to. Theonly thing the stored procedures do is a select statement on a fewtables that are joined. In the last few weeks we have experiencedissues where, two or three of these stored procedures consistentlytimeout. When we recompile the stored procedures, the problem goesaway for a period of time (anywhere between a few hours and a fewdays), then it reoccurs with the same two or three stored procedures.We have tried running the stored procedures with the same parametersagainst the same server using query analyzer with the same user andconnection settings while we are having the timeout issues, and theyperformed normally (in the 5 second range). We have also put thedatabase into "read only" mode, which has improved performanceduring normal times, but the issue continues to occur.Our trace data shows that during the timeouts periods, the storedprocedures perform the same number of reads and writes, and using thesame amount of CPU as during normal times, but the duration increasesfrom 5-6 seconds to 30 seconds (when the server receives the timeoutrequest).We have found no blocking on any of the tables (they are, after all,read only).Finally, we compared execution plans for the stored procedures when wehad timeouts to right after we recompile and alleviate the issue, andthe plans are identical.What could be causing this problem? Does recompiling a storedprocedure affect the Sql Server .Net Data provider?Thanks in advance
View 1 Replies
View Related
Sep 3, 2005
Sory for starting a new message, it won't let me reply to the original.Problem has been solved.osql -U sa -s localhostBALTDDoes the trick.Thanks for everyone who had a look at it anyway!Enjoy your weekend!
View 1 Replies
View Related
Mar 29, 2008
I have 15 websites running on my server, which also has SQL Express installed.
every other day my webpages whch connect by sql connection string, give an error.
Event Type: Failure Audit
Event Source: MSSQL$SQLEXPRESS
Event Category: (4)
Event ID: 18456
Date: 29/03/2008
Time: 18:20:07
User: N/A
Computer: DSVR006063
Description:
Login failed for user 'db'. [CLIENT: <local machine>]
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
Data:
0000: 18 48 00 00 0e 00 00 00 .H......
0008: 16 00 00 00 44 00 53 00 ....D.S.
0010: 56 00 52 00 30 00 30 00 V.R.0.0.
0018: 36 00 30 00 36 00 33 00 6.0.6.3.
0020: 5c 00 53 00 51 00 4c 00 .S.Q.L.
0028: 45 00 58 00 50 00 52 00 E.X.P.R.
0030: 45 00 53 00 53 00 00 00 E.S.S...
0038: 07 00 00 00 6d 00 61 00 ....m.a.
0040: 73 00 74 00 65 00 72 00 s.t.e.r.
0048: 00 00
Restarting SQL Service does not resolve, however rebooting server, without making any changed sorts the problem.
does my sql account need access to the master?
Is this weird or am i missing something really obvious.
View 8 Replies
View Related
Jul 23, 2005
Hi,As I wrote my message the solution came to me, so I thought I wouldpost anyway for others to see in case it was useful:Here is some sample DDL for this question:CREATE TABLE Source (my_value INT NOT NULL )GOINSERT INTO Source VALUES (1)INSERT INTO Source VALUES (2)INSERT INTO Source VALUES (3)GOCREATE TABLE Destination (value_type VARCHAR(10) NOT NULL,value INT )GOI would like to fill the destination with a row for the COUNT, SUM,MIN, and MAX. My own problem is of course much more complex than this,but this is the basic stumbling block for me now. So, the rows that Iwould expect to see in Destination are:value_type value---------- -----COUNT 3SUM 6MIN 1MAX 3The solution that I came up with was to add a Value_Types table:CREATE TABLE Value_Types (value_type VARCHAR(10) NOT NULL )GOINSERT INTO Value_Types VALUES ('COUNT')INSERT INTO Value_Types VALUES ('SUM')INSERT INTO Value_Types VALUES ('MAX')INSERT INTO Value_Types VALUES ('MIN')GONow the SQL is pretty simple:SELECT V.value_type,CASE V.value_typeWHEN 'COUNT' THEN COUNT(*)WHEN 'SUM' THEN SUM(S.my_value)WHEN 'MAX' THEN MAX(S.my_value)WHEN 'MIN' THEN MIN(S.my_value)ENDFROM Source SINNER JOIN Value_Types V ON 1=1-Tom.P.S. - I know that I did not include primary or foreign keys in my DDL.I'll leave it as an excercise to the reader to figure those out. Ithink the code adequately explains the concept.
View 3 Replies
View Related
Jan 28, 2008
As an example, I have a scalar function called TRIM that takes a VARCHAR parameter, does a LTRIM(TRIM(VARCHAR)), and returns the result.
How can I call this function from java using JDBC? I have only had luck calling basic stored procedures, but I need to call functions as well.
Thanks, Ken
View 1 Replies
View Related
Jan 24, 2005
I have a table which contains suppliers that can supply certain articles.
There can be many suppliers to each article, and therefore there is a field that tells you if this supplier is the main supplier for the article, this field is called "arthuvudavt". However, you aren't forced to use this field in the table.
As a alternative you can use priority. Each supplier has given priority where
0 means "most preferred" and any other means "less preferred"
What I want to do is to pick the right supplier for a given article in one SQL-statement regardless of if you choose to use the priority or if you choose to use the main supplier field.
Abbreviated description of the table, called AL.
SuppNo Article Arthuvudavt Prio
10101 A-10 NULL 0
10202 A-10 1 0
10303 A-10 NULL 1
10101 B-10 NULL 0
10202 B-10 NULL 0
10303 B-10 NULL 1
10101 C-10 NULL 1
10202 C-10 NULL 0
10303 C-10 NULL 1
In the above case, I'd like the statement to return supplier 10202 for article A-10 (the one that has the arthuvudavt checked), and
only one row for B-10, which one doesn't really matter, since someone has been making a fault here, this should not happen, but my SQL-statement should break because of this scenario. For C-10 supplier 10303 should be returned.
Is there any way this could be done?
The reason I ask is that I try to learn new ways of solving things, and this problem was kind'a easily solved using variables, but I was wondering if it was possible to do it without it.
Thanks in advance
Jonas
Sorry for the poor formatting, I didn't have the time to make it right.
View 14 Replies
View Related
May 2, 2008
Hi,
I have a report in which a developper has put a matrix which has 4 MatrixRows.
I want to delete 2 of them.
When I righlt click a row and click Delete there is message about rows groups and columns groups and the row is still there.
When I right click the matrix and go to properties / group, i see Row group = [Static group] and I cannot modify it.
How can I delete a MatrixRow ?
a+, =)
-=Clement=-
Configuration :
SQL Server 2005
edit :
I found the solution : click on the cell in the 2nd column, not in the first, then right click and delete.
I would suggest Microsoft IT s to put less humor in their softs (you click delete in the wrong place, you get a weird message instead of a 'try another cell' )
View 1 Replies
View Related
Apr 18, 2006
hi
I am trying to store the output of sp-executesql into a variable to implement it as a user defined function later
The function is
ALTER function [dbo].[UnitsAvailable] (@id int)
returns int
as
begin
declare @sql nvarchar(100)
declare @params nvarchar(500)
declare @count nvarchar(10)
set @sql = N'Select count(*) from units where projectid=' + convert(varchar,@id) + 'and sold=0 and displayunit=1'
set @params = N'@countOUT nvarchar(10) OUTPUT';
exec sp_executesql @sql, @params, @countOUT=@count OUTPUT;
return @count
end
The result is that I am able to parameterize the sql end execute with the right result. The only problem is that the value is not stored in the variable @count. I could get to the same result using managed code in sql 2005 but still I am curious to find out where the problem is ....
Can you please help?
Thanks Alex
View 6 Replies
View Related
Nov 13, 2005
solution found here:
View 1 Replies
View Related