Cast From String &"&" To Type 'Date' Is Not Valid

Mar 12, 2006

Hello, I am using an SQLDataReader called DrCoInfo to check if any matching records exist in a table.

My code is as such:

Line 119:DrCoInfo = comm1.ExecuteReader()
Line 120:While DrCoInfo.Read()
Line 121: If DrCoInfo("DateOfMan") <> "" Then
Line 122: BValid = True
Line 123: End If

However, it fails to work with the message :System.InvalidCastException: Cast from string "" to type 'Date' is not valid.

Any suggestions? Thanks.

View 4 Replies


ADVERTISEMENT

Cast From String 'OPEN' To Type 'Double' Is Not Valid.

Aug 12, 2007

Hi.. Please help me resolve this error "Cast from string 'OPEN' to type 'Double' is not valid.". Error here If CallStatus = 10 Then ....Code:Public Sub UpdateCallStatus()        Dim CALLID, RequestorID, CommentsFromITD, MessageFromITD, MessageToITD, CallStatus, strSQL As String        CALLID = Request.QueryString("CallID")        RequestorID = Session("USER_ID")        CommentsFromITD = lblcomments.Text        MessageFromITD = lblmessage.Text        MessageToITD = txt_desc.Text        CallStatus = Trim(Request.Form(ddl_callstatus.UniqueID))
        Dim ObjCmd As SqlCommand        Dim ObjDR As SqlDataReader
        Try            If CallStatus = 10 Then                strSQL = "UPDATE CALLS  SET STATUS_ID=" & CallStatus & " WHERE CALL_ID=  " & CALLID & ""                ObjCmd = New SqlCommand(strSQL, ObjConn)                ObjConn.Open()                ObjDR = ObjCmd.ExecuteScalar()                gbVariables.insertuserevents(CALLID, RequestorID, "Call Closed")                Response.Redirect("UserCallClosed.aspx")                ObjConn.Close()            Else                strSQL = "UPDATE CALLS  SET STATUS_ID=" & CallStatus & " WHERE CALL_ID=  " & CALLID & ""                ObjCmd = New SqlCommand(strSQL, ObjConn)                ObjConn.Open()                ObjDR = ObjCmd.ExecuteScalar()                ObjConn.Close()
                strSQL = "SELECT STATUS_LABEL  FROM STATUS WHERE STATUS_ID = " & CallStatus & ""                ObjCmd = New SqlCommand(strSQL, ObjConn)                ObjConn.Open()                ObjDR = ObjCmd.ExecuteScalar()                ObjConn.Close()
                gbVariables.insertuserevents(CALLID, RequestorID, CallStatus)                CallStatus = ""            End If        Catch ex As Exception            lblmsg.Text = ex.Message.ToString        End Try    End SubThanks...

View 1 Replies View Related

Reporting Services :: Conversion From String 20041023 To Type Date Is Not Valid

Apr 18, 2015

I have a table with one of the column(EmpHiredate) datatype is char(10). It has value like "20141023". I need to display this value as date format(dd/mm/yyyy) in report. Following methods i tried in textbox expression but no luck.

=Format(Fields!EmpHireDate.Value,"dd/MM/yyyy")
=Cdate(Fields!EmpHireDate.Value)

Error:[rsRuntimeErrorInExpression] The Value expression for the textrun ‘EmpHireDate.Paragraphs[0].TextRuns[0]’ contains an error: Conversion from string "20041023  " to type 'Date' is not valid.

Is it possible to convert string to date using SSRS textbox expression ?

View 7 Replies View Related

Conversion From Type 'DBNull' To Type 'String' Is Not Valid

Mar 7, 2008

Hello Friends
           How are you?? Friends i am getting problem in SQL Server 2005. I am deployng web application on production server as well as Databse also. In production server i inserted new field in all tables which is rowguid and its type is uniqueidentifier. The default binding for this field is newsequentialid(). In some pages it works ok but in some places it generates error like 'Conversion from type 'DBNull' to type 'String' is not valid'. Can anybody help me to solve this problem. Its urgent so plz reply me as soon as possible. I'll be very thankfull to you. Thanks in Advance.
 Regards,

View 1 Replies View Related

SqlDataSource.Select Error: Unable To Cast Object Of Type 'System.Data.DataView' To Type 'System.String'.

Oct 19, 2006

I am trying to put the data from a field in my database into a row in a table using the SQLDataSource.Select statement. I am using the following code: FileBase.SelectCommand = "SELECT Username FROM Files WHERE Filename = '" & myFileInfo.FullName & "'" myDataRow("Username") = CType(FileBase.Select(New DataSourceSelectArguments()), String)But when I run the code, I get the following error:Server Error in '/YorZap' Application. Unable to cast object of type 'System.Data.DataView' to type 'System.String'. 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: Unable to cast object of type 'System.Data.DataView' to type 'System.String'.Source Error: Line 54: FileBase.SelectCommand = "SELECT Username FROM Files WHERE Filename = '" & myFileInfo.FullName & "'"
Line 55: 'myDataRow("Username") = CType(FileBase.Select(New DataSourceSelectArguments).GetEnumerator.Current, String)
Line 56: myDataRow("Username") = CType(FileBase.Select(New DataSourceSelectArguments()), String)
Line 57:
Line 58: filesTable.Rows.Add(myDataRow)Source File: D:YorZapdir_list_sort.aspx    Line: 56 Stack Trace: [InvalidCastException: Unable to cast object of type 'System.Data.DataView' to type 'System.String'.]
ASP.dir_list_sort_aspx.BindFileDataToGrid(String strSortField) in D:YorZapdir_list_sort.aspx:56
ASP.dir_list_sort_aspx.Page_Load(Object sender, EventArgs e) in D:YorZapdir_list_sort.aspx:7
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45
System.Web.UI.Control.OnLoad(EventArgs e) +80
System.Web.UI.Control.LoadRecursive() +49
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3743
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210 Please help me!

View 3 Replies View Related

Unable To Cast Object Of Type 'System.String' To Type 'System.Web.UI.WebControls.Parameter'.

Jun 19, 2008

I'm getting this error on a vb.net page the needs to execute two separate stored procedures.  The first one, is the main insert, and returns the identity value for the ClientID.  The second stored procedure inserts data, but needs to insert the ClientID returned in the first stored procedure.  What am I doing wrong with including the identity value "ClientID" in the second stored procedure? 
Unable to cast object of type 'System.String' to type 'System.Web.UI.WebControls.Parameter'. 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: Unable to cast object of type 'System.String' to type 'System.Web.UI.WebControls.Parameter'.Source Error:




Line 14: If li.Selected Then
Line 15: InsertClientCompanyType.InsertParameters("CompanyTypeID").DefaultValue = li.Value
Line 16: InsertClientCompanyType.InsertParameters("ClientID") = ViewState("ClientID")
Line 17:
Line 18:
Source File: C:InetpubwwwrootIntranetExternalAppsNewEmploymentClientNewClient.aspx.vb    Line: 16
Here is my code behind... What am I doing wrong with grabbing the ClientID from the first stored procedure insert? 
 
Protected Sub InsertNewClient_Inserted(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)ClientID.Text = e.Command.Parameters("@ClientID").Value.ToString()ViewState("ClientID") = e.Command.Parameters("@ClientID").Value.ToString()End SubProtected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.ClickInsertNewClient.Insert()For Each li As ListItem In CompanyTypeID.Items
If li.Selected ThenInsertClientCompanyType.InsertParameters("CompanyTypeID").DefaultValue = li.ValueInsertClientCompanyType.InsertParameters("ClientID") = ViewState("ClientID")InsertClientCompanyType.Insert()End IfNextEnd Sub

View 2 Replies View Related

Type Cast Error Converting From Integer To String

Oct 30, 2007

I am attempting to convert an integer value to a string using the Derived Column transformation with the following expression on the field:
(DT_STR,10,1252)prod_id

prod_id is an integer. I was able to do this before however, in the past couple of days, this has failed with the following error:
"An error occurred while attempting to perform a type cast."


To my knowledge, I have not changed anything about this particular data flow within the past couple of days. I have verified that the value is coming in as an integer.

Any help would be greatly appreciated.

View 7 Replies View Related

Unable To Cast Object Of Type 'System.DateTime' To Type 'System.String'.

Dec 31, 2007

 Hi,      I got this field (dateSubmitted) having a data type of DateTime but I receive this error "Unable to cast object of type 'System.DateTime' to type 'System.String'."       All value for dateSubmitted field are 12/27/2007 12:00:00 AM. cheers,imperialx 

View 3 Replies View Related

Unable To Cast Object Of Type 'System.String' Error Help

Aug 1, 2007

Unable to cast object of type 'System.String' to type 'System.Web.UI.DataSourceSelectArguments'.
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: Unable to cast object of type 'System.String' to type 'System.Web.UI.DataSourceSelectArguments'. 
Hi, In my pageload i have data retriving from a page and i want it to load it in the GridView. i have GridView and SqlDataSource but when the page loads i am getting the above error. i am not sure what im doing wrong here. i tried different ways. but no luck Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Thenfp = CType(Context.Handler, Member)
'lblEmail.Text = fp.EMM.ToString
'this labelbox for Email address is under the Name'lblEmail.Text = fp.EmailAddress.ToString
 
 Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("imacstestConnectionString").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand("SELECT , [fname], [mname], [lname], [address], [city], [state], [zip], [phone] FROM [t_CustomerAcct] WHERE = @email", conn)cmd.Parameters.AddWithValue("@email", fp.EMM.ToString)
conn.Open()
SqlDataSource1.Select(cmd.ExecuteScalar())
'.ExecuteScalar()
 
conn.Close()
End If
End Sub

View 1 Replies View Related

Cast From String To Date

Sep 21, 2006

I created an SSIS package that pulls in legacy data from a DB2 AS400. There is an In Date field that is stored on the AS400 as OdbcType.Date or DATE. However, when I use SSIS to pull in the data, SQL wants it to be a string so I gave up and let SQL have it's way.

Now in my SELECT statement, I have this:

SELECT TLMST.TLNUMBER, TLMST.DOGNAM, BRDMST.BRDesc, TLMST.INDT
FROM TLMST INNER JOIN
BRDMST ON TLMST.BRDCOD = BRDMST.BreedNumber
WHERE (TLMST.INDT >= @startdate) AND (TLMST.INDT <= @enddate)
ORDER BY TLMST.INDT, TLMST.TLNUMBER

Because I see the dates stored in TLMST are yyyy-mm-dd format, this is not working. It is not pulling any records. I tried to use the CAST statement but I keep getting errors about casting from a string to a date and data overflow errors.

Should I go back and re-do the SSIS or is there a way to pull the records for this? Thanks for the information

View 5 Replies View Related

Conditional Statement With A Cast From String To Date

Feb 5, 2007

My source file is showing column 10 as string. My destination table is datetime. I am using the derived transformation with a conditional statement. How do I convert the value from string to date. Everywhere I try the (DT_DATE) I get an error.

[Column 10] == "01/01/0001" ? " 01/01/1801" : [Column 10] <= "12/31/1801" ? "12/31/1801" : [Column 10]

View 9 Replies View Related

Specified Cast Is Not Valid

Sep 11, 2006

im doing a sum on a table and it either returns a number in decimal format or 'null' .  The problem is when it returns null i want it to just make the text say '0.00'.  So i did a test on the object that if it returns NULL just print  '0.00' but if it is not null it tells me that there is a number there and i want to store that as a decimal and print it out.  But i get an error for a type cast when im not it should not even be going to that part of the code. In the code below the first executescaler will return null so it should just go straight to the else.  But it gives me the type cast error in the if that shouldnt be seen.  The error and code are below. //Borrower NSF FEES
cmd.CommandText = "select sum(itemamount) from postmtdtls where loanid='" + LoanID + "' and Transactioncode = '310'";
object temp = cmd.ExecuteScalar();
if (temp != null)
{
decimal B_NSFFees = ((decimal)cmd.ExecuteScalar());
borrowerPayoff_NSFFees.Text = String.Format("{0:#,#.##}", B_NSFFees).ToString(); //Borrower NSF FEES
}
else
{
borrowerPayoff_NSFFees.Text = "0.00"; //borrowerPayoff_NSFFees.Text = "0.00";
}  Server Error in '/WebSite5' Application. Specified cast is not valid. 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: Specified cast is not valid.Source Error: Line 774: if (temp != null)
Line 775: {
Line 776: decimal B_NSFFees = ((decimal)cmd.ExecuteScalar());
Line 777: borrowerPayoff_NSFFees.Text = String.Format("{0:#,#.##}", B_NSFFees).ToString(); //Borrower NSF FEES
Line 778: }Source File: c:ProgrammingFilesWebSite5InvestorPool.aspx.cs    Line: 776 Stack Trace: [InvalidCastException: Specified cast is not valid.]
InvestorPool.GetLoanInfo(String LoanID) in c:ProgrammingFilesWebSite5InvestorPool.aspx.cs:776
InvestorPool.MortAccountText(Object sender, EventArgs e) in c:ProgrammingFilesWebSite5InvestorPool.aspx.cs:660
System.Web.UI.WebControls.TextBox.OnTextChanged(EventArgs e) +75
System.Web.UI.WebControls.TextBox.RaisePostDataChangedEvent() +124
System.Web.UI.WebControls.TextBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +7
System.Web.UI.Page.RaiseChangedEvents() +138
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4507
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42

View 10 Replies View Related

Specified Cast Is Not Valid

Apr 7, 2006

Can't seem to find why I'm getting this error: Specified cast is not valid.
Ok, using a stored procedure for SQL Server 2000 and here is the main part of it:
 SELECT id, rank, firstName, lastName, service, status, createdTime FROM   accessRequest WHERE  lastName LIKE @tLastName     AND    firstName LIKE @tFirstName
And the C# code behind from the class file:
SqlDataReader spResults;
conn.Open();
spResults = command.ExecuteReader();
while( spResults.Read() )
{
AccessRequestSearch request = new AccessRequestSearch( (int)spResults.GetInt32( 0 ), spResults.GetString( 2 ), spResults.GetString( 3 ), spResults.GetString( 1 ), spResults.GetString( 4 ), spResults.GetString( 5 ), Convert.ToDateTime(spResults.GetString( 6 )));
searchResults.Add( request ); // Add to Array List
}
spResults.Close();
The part in red is where I think it's happening because that is what I just added to the request.  createdTime in the table is set as DateTime.
Can anyone see what I am missing here?
More info is available if needed.
Thanks,
Zath

View 1 Replies View Related

Error: Specified Cast Is Not Valid.

Jul 11, 2006

 
 
  sqlConnection1.Open();
System.Data.SqlClient.SqlDataReader Dil1;
Dil1 = sqlDilGetir.ExecuteReader();
ddlDil1.Items.Add(new ListItem("1. Dil", ""));
while (Dil1.Read())
{
ddlDil1.Items.Add(new ListItem(Dil1.GetString(1), Dil1.GetString(0)));
}
Dil1.Close();
sqlConnection1.Close(); 

View 7 Replies View Related

SSRS2000 - Specifies Cast Not Valid

May 2, 2007

Hi,



I get the above error everytime I try to export to Excel; exporting to PDF works fine.



The only way I can get rid of the error is by deleting all the data from within the report (not ideal!). Anyone got any ideas on what could be causing this?



Many thanks,



Mani

View 1 Replies View Related

DB Engine :: Error Specified Cast Is Not Valid

May 25, 2015

I have a backup of DB with version Microsoft sql 2012 and i need restore this data base on instance Microsoft sql 2008 R2
when i try restore database on SQL server 2008 R2  i have the error:

Specified cast is not valid.
(SqlManagerUI)

View 6 Replies View Related

DB Backup Is Not Being Restored To Another DB - Specified Cast Is Not Valid

May 12, 2015

I have been experiencing "Specified cast is not valid" error while restoring backup of DB. Version of SQL server management tool from which I am taking the backup is "Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86) Jun 17 2011 00:57:23 Copyright (c) Microsoft Corporation Express Edition with Advanced Services on Windows NT 6.1 (Build 7601: Service Pack 1) (WOW64) (Hypervisor) ". And restoring to the same version tool.

I have tried all the workarounds like TSQL, Upgrade the version of restoring DB to higher version, MDF and LDF files generation. But they are not working.

View 12 Replies View Related

Cannot Show The Editor For This Task. Specified Cast Is Not Valid

Jul 26, 2006

This error is pretty persistent. I re-installed VS 2005 and SQL Server 2005 but did not help. Every time I try to open a Script Task editor it gives me the same error regardless of the project or package. DO I NEED TO REBUILD MY SYSTEM ?

===================================

Cannot show the editor for this task. (Microsoft Visual Studio)

===================================

Specified cast is not valid. (Microsoft.VisualBasic.Vsa.DT)

------------------------------
Program Location:

   at Microsoft.VisualBasic.Vsa.Dt.VsaIDE.get_ExtensibilityObject()
   at Microsoft.SqlServer.VSAHosting.DesignTime.get_ExtensibilityObject()
   at Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptTaskUI.Dispose()
   at Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptTaskMainWnd.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at Microsoft.DataTransformationServices.Design.DtrPackageDesigner.DoDefaultActionForTask(TaskHost task)

 

-------

Any help is appreciated.

Gulden

 

.......

View 9 Replies View Related

Specified Cast Is Not Valid Error In Datagrid/update Script

Oct 5, 2006

I have a datagrid script where I modify data in an sql dbase in asp.net, when i hit the "update" button, I get a Specified cast is not valid error on my 'descript' declaration, whereas 'descript' is a multiline text box and a varchar datatype (everything else is either a char or a datetime datatype). Am I assigning 'descript' a wrong datatype? Tried making it a nvarchar, still get same result'''''''''''''''''''''''''''''''Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs ) Dim conn As SQLConnection Dim MyCommand As SQLCommand Dim strConn as string = "Server=sql.mydomain.com;Initial Catalog=mydb;User ID=DBxxx;Password=xxxxx;" Dim company As textbox = E.Item.cells(2).Controls(0) Dim address As textbox = E.Item.cells(3).Controls(0) Dim city As textbox = E.Item.Cells(4).Controls(0)  Dim state As textbox = E.Item.cells(5).Controls(0) Dim county As textbox = E.Item.cells(6).Controls(0) Dim zip As textbox = E.Item.cells(7).Controls(0) Dim phone As textbox = E.Item.cells(8).Controls(0)'''''' the following line declaring the descript var is the line of the error Dim descript As textbox = E.Item.cells(9).Controls(0) Dim web As textbox = E.Item.cells(10).Controls(0) Dim email As textbox = E.Item.cells(11).Controls(0) Dim datesold As textbox = E.Item.cells(12).Controls(0) Dim dateexpire As textbox = E.Item.cells(13).Controls(0)  Dim strUpdateStmt As String        strUpdateStmt =" UPDATE CPAs SET" & _        " company = @company, address = @address, city = @city, state = @state, " & _        "county = @county, zip = @zip, phone = @phone, descript =@ descript, " & _  "web = @web, email = @email, datesold = @datesold, dateexpire = @dateexpire" & _  " WHERE cpaID = @cpaID" conn = New SqlConnection(strConn) MyCommand = New SqlCommand(strUpdateStmt, conn) MyCommand.Parameters.Add(New SqlParameter("@company", company.text)) MyCommand.Parameters.Add(New SqlParameter("@address", address.text)) MyCommand.Parameters.Add(New SqlParameter("@city", city.text)) MyCommand.Parameters.Add(New SqlParameter("@state", state.text)) MyCommand.Parameters.Add(New SqlParameter("@county", county.text)) MyCommand.Parameters.Add(New SqlParameter("@zip", zip.text)) MyCommand.Parameters.Add(New SqlParameter("@phone", phone.text)) MyCommand.Parameters.Add(New SqlParameter("@descript", descript.text)) MyCommand.Parameters.Add(New SqlParameter("@web", web.text)) MyCommand.Parameters.Add(New SqlParameter("@email", email.text)) MyCommand.Parameters.Add(New SqlParameter("@datesold", datesold.text)) '', dateexpire =@dateexpire MyCommand.Parameters.Add(New SqlParameter("@dateexpire", dateexpire.text))  MyCommand.Parameters.Add(New SqlParameter("@cpaID", e.Item.Cells(1).Text )) conn.Open() MyCommand.ExecuteNonQuery() MyDataGrid.EditItemIndex = -1        conn.close BindDataEnd Sub'''''''''''''''''''''''''''''netsports

View 1 Replies View Related

Conversion From Type 'SqlInt32' To Type 'Integer' Is Not Valid]

Jun 30, 2007

Hi all,
I am developing ASP.NET 1.1 application using VB.NET & SQL Server, on my machine I am using SQL Server 2000, and everything is working just fine.
The problem appears when I uploaded the site to the Host, they are using SQL Server 2005, is there any reason for this, I am using casting in the code, and I am sure there is something wrong with the hosting settings.
Any suggestions.
Best Regards
Wafi Mohtaseb

View 4 Replies View Related

Conversion From String To Type Date Error

Mar 20, 2008

 I have a web page which executes a stored procedure with several parameters. On execution I get an error for the following piece of code. I will be passing null value to the stroed procedure for this parameter "ActiveDate". 
Dim parameterActivedate As SqlParameter = objCommand.Parameters.Add("@Activedate", SqlDbType.DateTime)
parameterActivedate.Value = ""
The error is:
System.InvalidCastException: Conversion from string "" to type 'Date' is not valid. at Microsoft.VisualBasic.CompilerServices.Conversions.ToDate(String Value) at webpage.Do_Update(Object Sender, EventArgs e) 

View 3 Replies View Related

Unable To Cast COM Object Of Type 'System.__ComObject' To Class Type 'System.Data.SqlClient.SqlConn

May 17, 2006

Dear all,

I am stuck with a SSIS package and I can€™t work out. Let me know what steps are the correct in order to solve this.
At first I have just a Flat File Source and then Script Component, nothing else.

Error:





[Script Component [516]] Error: System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'System.Data.SqlClient.SqlConnection'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface. at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(Exception e) at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.AcquireConnections(Object transaction) at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostAcquireConnections(IDTSManagedComponentWrapper90 wrapper, Object transaction)



Script Code (from Script Component):



' Microsoft SQL Server Integration Services user script component
' This is your new script component in Microsoft Visual Basic .NET
' ScriptMain is the entrypoint class for script components

Imports System
Imports System.Data.SqlClient
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper


Public Class ScriptMain
Inherits UserComponent


Dim nDTS As IDTSConnectionManager90
Dim sqlConnecta As SqlConnection
Dim sqlComm As SqlCommand
Dim sqlParam As SqlParameter


Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

Dim valorColumna As String
Dim valorColumna10 As Double


valorColumna = Row.Column9.Substring(1, 1)

If valorColumna = "N" Then
valorColumna10 = -1 * CDbl(Row.Column10 / 100)
Else
valorColumna10 = CDbl(Row.Column10 / 100)
End If

Me.Output0Buffer.PORCRETEN = CDbl(Row.Column11 / 100)
Me.Output0Buffer.IMPRETEN = CDbl(Row.Column12 / 100)
Me.Output0Buffer.EJERCICIO = CInt(Row.Column2)
Me.Output0Buffer.CODPROV = CInt(Row.Column7)
Me.Output0Buffer.MODALIDAD = CInt(Row.Column8)
Me.Output0Buffer.NIFPERC = CStr(Row.Column3)
Me.Output0Buffer.NIFREP = CStr(Row.Column4)
Me.Output0Buffer.NOMBRE = CStr(Row.Column6)
Me.Output0Buffer.EJERDEV = CDbl(Row.Column13)

With sqlComm
.Parameters("@Ejercicio").Value = CInt(Row.Column2)
.Parameters("@NIFPerc").Value = CStr(Row.Column3)
.Parameters("@NIFReP").Value = CStr(Row.Column4)
.Parameters("@Nombre").Value = CStr(Row.Column6)
.Parameters("@CodProv").Value = CInt(Row.Column7)
.Parameters("@Modalidad").Value = CInt(Row.Column8)
.Parameters("@ImpBase").Value = valorColumna10
.Parameters("@PorcReten").Value = CDbl(Row.Column11 / 100)
.Parameters("@ImpReten").Value = CDbl(Row.Column12 / 100)
.Parameters("@EjerDev").Value = CDbl(Row.Column13)

.ExecuteNonQuery()
End With


End Sub
Public Overrides Sub AcquireConnections(ByVal Transaction As Object)

Dim nDTS As IDTSConnectionManager90 = Me.Connections.TablaMODELO80
sqlConnecta = CType(nDTS.AcquireConnection(Nothing), SqlConnection)

End Sub
Public Overrides Sub PreExecute()

sqlComm = New SqlCommand("INSERT INTO hac_modelo180(Ejercicio,NIFPerc,NIFReP,Nombre,CodProv,Modalidad,ImpBase,PorcReten,ImpReten,EjerDev) " & _
"VALUES(@Ejercicio,@NIFPerc,@NIFReP,@Nombre,@CodProv,@Modalidad,@ImpBase,@PorcReten,@ImpReten,@EjerDev)", sqlConnecta)
sqlParam = New SqlParameter("@Ejercicio", Data.SqlDbType.SmallInt)
sqlComm.parameters.add(sqlParam)
sqlParam = New SqlParameter("@NIFPerc", Data.SqlDbType.Char)
sqlComm.parameters.add(sqlParam)
sqlParam = New SqlParameter("@NIFReP", Data.SqlDbType.Char)
sqlComm.parameters.add(sqlParam)
sqlParam = New SqlParameter("@Nombre", Data.SqlDbType.VarChar)
sqlComm.parameters.add(sqlParam)
sqlParam = New SqlParameter("@CodProv", Data.SqlDbType.TinyInt)
sqlComm.parameters.add(sqlParam)
sqlParam = New SqlParameter("@Modalidad", Data.SqlDbType.SmallInt)
sqlComm.parameters.add(sqlParam)
sqlParam = New SqlParameter("@ImpBase", Data.SqlDbType.Decimal)
sqlComm.parameters.add(sqlParam)
sqlParam = New SqlParameter("@PorcReten", Data.SqlDbType.Decimal)
sqlComm.parameters.add(sqlParam)
sqlParam = New SqlParameter("@ImpReten", Data.SqlDbType.Decimal)
sqlComm.parameters.add(sqlParam)
sqlParam = New SqlParameter("@EjerDev", Data.SqlDbType.Decimal)
sqlComm.Parameters.Add(sqlParam)

End Sub


Public Sub New()

End Sub
Public Overrides Sub ReleaseConnections()
nDts.ReleaseConnection(sqlConnecta)
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class







Thanks a lot for your help


View 13 Replies View Related

@PARAM1 : Unable To Cast Object Of Type 'System.Data.SqlTypes.SqlInt32 To Type System.IConvertable

Apr 23, 2007

I get the following message in the vs2005 querybuilder when i do a preview:



***********************************
SQL Execution Error.

Executed SQL statement: SELECT Schoolindex, Variant, VVSchool, [index], indincl, VVRuimtes, School FROM School WHERE (Schoolindex = @PARAM1)



Error Source: SQL Server Compact Edition ADO.NET Data Provider


Error Message: @PARAM1 : Unable to cast object of type 'System.Data.SqlTypes.SqlInt32 to type System.IConvertable'.
****************************************

The same querypreview works fine without the parameter:



SELECT Schoolindex, Variant, VVSchool, [index], indincl, VVRuimtes, School FROM School WHERE (Schoolindex = 186)



Can anybody tell me why this is?
And tell me a way to get the tableadapter working?



Anne-Jan Tuinstra

View 3 Replies View Related

Unable To Cast COM Object Of Type 'ADODB.CommandClass' To Interface Type 'ADODB._Command'

Dec 20, 2006

I have an application which runs successfully on a couple of my customer's machines but fails on a third. It seems to fail when opening the database:

Unable to cast COM object of type 'ADODB.CommandClass' to interface type 'ADODB._Command'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B08400BD-F9D1-4D02-B856-71D5DBA123E9}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=false; Initial Catalog=lensdb;Data Source = SQL

Before I got this error I was getting another problem (sorry didn't make a copy of that error's text) that made me think that adodb.dll simply wasn't loaded/registered. I got rid of that error by copying my adodb.dll onto the third machine and running gacutil /i. There is now an entry in winntassemblies for adodb.

Just in case you think it could be an obvious registry problem: when I started getting the current error I thought that maybe the registry needed updating and I merged the following lines into onto the target machine (from my dev machine):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOTInterface{B08400BD-F9D1-4D02-B856-71D5DBA123E9}]
@="_Command"

[HKEY_CLASSES_ROOTInterface{B08400BD-F9D1-4D02-B856-71D5DBA123E9}ProxyStubClsid]
@="{00020424-0000-0000-C000-000000000046}"

[HKEY_CLASSES_ROOTInterface{B08400BD-F9D1-4D02-B856-71D5DBA123E9}ProxyStubClsid32]
@="{00020424-0000-0000-C000-000000000046}"

[HKEY_CLASSES_ROOTInterface{B08400BD-F9D1-4D02-B856-71D5DBA123E9}TypeLib]
@="{EF53050B-882E-4776-B643-EDA472E8E3F2}"
"Version"="2.7"

[HKEY_LOCAL_MACHINESOFTWAREClassesInterface{B08400BD-F9D1-4D02-B856-71D5DBA123E9}]
@="_Command"

[HKEY_LOCAL_MACHINESOFTWAREClassesInterface{B08400BD-F9D1-4D02-B856-71D5DBA123E9}ProxyStubClsid]
@="{00020424-0000-0000-C000-000000000046}"

[HKEY_LOCAL_MACHINESOFTWAREClassesInterface{B08400BD-F9D1-4D02-B856-71D5DBA123E9}ProxyStubClsid32]
@="{00020424-0000-0000-C000-000000000046}"

[HKEY_LOCAL_MACHINESOFTWAREClassesInterface{B08400BD-F9D1-4D02-B856-71D5DBA123E9}TypeLib]
@="{EF53050B-882E-4776-B643-EDA472E8E3F2}"
"Version"="2.7"


but, no change alas.

All three machines are running Windows 2000.

Any advice would be appreciated.

Thanks in advance,

Ross

View 1 Replies View Related

T-SQL (SS2K8) :: Conversion Failed When Converting Character String To Small Date-time Data Type

Jul 15, 2014

All source and target date fields are defined as data type "smalldatetime". The "select" executes without error though when used with "insert into" it fails with the error:

Msg 295, Level 16, State 3, Line 25: Conversion failed when converting character string to small date-time data type..I am converting from a character string to smalldatetime since the source and target date columns are "smalldatetime". All other columns for the source and target are nvarchar(255). I assume there is an implicit conversion that I don't understand. In a test, I validated that all dates selected evaluate ISDATE() to 1.

USE [SCIR_DataMart_FromProd_06_20_2014]
GO
IF OBJECT_ID ('[SCIR_DataMart_FromProd_06_20_2014].[dbo].[IdentifierLookup]', 'U') IS NOT NULL
DROP TABLE [SCIR_DataMart_FromProd_06_20_2014].[dbo].[IdentifierLookup]

[code]....

View 9 Replies View Related

Unable To Cast Object Of Type 'System.DBNull' To Type 'System.Byte[]'.

Aug 13, 2007

Hi,
I have developed a custom server control for .NET Framework 2.0. The server control has a property named BinaryData of type byte[]. I marked this property to be data bindable. Now, I have varbinary(Max) type of field in my SQL Database and I have used SQLDataSource and bound this varbinary(Max) field with the property BinaryData (byte[]) of my control. It is working fine as long as the data value is not NULL. Now, In my control, I have handled the NULL value so that no Exception is thrown. Still, when I bind this property using the SQLDataSource, I get Error "Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'." I am not sure if I can do anything to stop this erro within my control. If it is not possible from the control, then what is the workaround that I can do in my ASPX page in order to stop this error ?
Thanks a lot in advance.

View 10 Replies View Related

Type Cast In Sql Query

Mar 17, 2008

Hello friends,
I am working on web application using sql server 2000, visual Studio 2005. In one of the table I have field 'NetAmount' purposely I had kept datatype as char. Now I want to update that field. for e.g. I have to add 100 to netAmount. How I can do it with sql query. Please let me know.
Thanks & RegardsGirish Nehte

View 1 Replies View Related

Type Cast Problem In SSIS

May 30, 2008

Correct me if i am wrong anywhere.


This is my table structure.


CREATE TABLE [AC].[RUN_PARMS](
[FILE_NAME] [varchar](6) NOT NULL,
[RUN_IND] [bit] NOT NULL,
[GROUP] [varchar](50) NULL,
CONSTRAINT [pk_RUN_PARMS] PRIMARY KEY CLUSTERED
(
[FILE_NAME]
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


I am using an execute package task in SSIS based on the value of RUN_IND field in RUN_PARMS table. If all the value of RUN_IND field is 0 for all the files in a group, then the execute package task should be enabled else it should be disabled. So i have used the following query.

SELECT SUM(CONVERT(INT,RUN_IND)) AS RUN_IND FROM AC.RUN_PARMS
WHERE [GROUP] = 'FIN'

This will return the value which will be greater than zero. Since i have made the value as 1 for FIN group. Imagine the FIN group has 10 files in it. The output look like,


RUN_IND
10

and

SELECT SUM(CONVERT(INT,RUN_IND)) AS RUN_IND FROM AC.RUN_PARMS
WHERE [GROUP] = 'Ven'

This will return the value which will be equal to zero. Since i have made the value as 0 for Ven group. The output look like,


RUN_IND
0


I have created a variable in the package "user::vardisablepackage".
I have set Resultset as Single for SQL task component
In the package properties (The package which has to be disabled) i have selected property as "Disable" and the expression as @User::vardisablepackage = 0 ?False:True

The problem now is i am not sure what should be the data type for vardisablepackage.
The expression will assign False to Disable property when the RUN_IND = 0.
I am unable to complete this task since i have problem assigning data type for this variable.

Please suggest your views.


Sarvan

View 4 Replies View Related

Error During Install: Not Valid For Machine Type

May 27, 2006

Hey all,

I am new to SQL 2005 and am getting an error stating my install is good but not for my machine type?

I am trying ot install 2005 Ent on a DL585 server with 4 CPUs and 12 GB of RAM.

Has anyone run into this?

View 1 Replies View Related

Cast String To Int

Apr 27, 2008

Hi ,

I have a problem with casting a string number to int.
for exmaple i have the number '0110' (string) and i would like it to be 110. or '0001' to be 1.
i tried to do:
cast(MyNUM as int) .
but i get "Syntax error converting the nvarchar value 'O322' to a column of data type int."

is anyone have any idea how to solve it ?

thanks

View 3 Replies View Related

Connection String Not Valid !

Apr 12, 2007

I've build a website with asp.net and on my local machine it run very we. but when I store my website on a server, I have a error : ...error: 25 - Connection String not valid...
This is my connection string on my local machine : "add name="csIyp" connectionString="data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|iyapason.mdf;User Instance=true" providerName="System.Data.SqlClient" "
And the connection string on my webserver : "add name="csIyp" connectionString="data source= .MSSQLSERVER;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|iyapason.mdf;User Instance=true" providerName="System.Data.SqlClient" "
So, what can I do to solve this probleme.
Thanks !

View 3 Replies View Related

Convert Datetime String To Datetime Date Type

Mar 11, 2014

I am inserting date and time data into a SQL Server 2012 Express table from an application. The application is providing the date and time as a string data type. Is there a TSQL way to convert the date and time string to an SQL datetime date type? I want to do the conversion, because SQL displays an error due to the

My date and time string from the application looks like : 3/11/2014 12:57:57 PM

View 1 Replies View Related

Unable To Cast Object Of Type 'System.Xml.XmlTextReaderImpl'

Jul 2, 2007

I'm getting the following error:  Unable to cast object of type 'System.Xml.XmlTextReaderImpl' to type 'System.Xml.XmlTextReader'. This works in .net 1.1 but having issues in the conversion to 2.0.
Public Function RunSPReturnXMLReader(ByVal strSP As String, ByVal ParamArray params() As SqlParameter) As System.Xml.XmlTextReader
Dim objHelperConnection As SqlConnectionobjHelperConnection = New SqlConnection(sConnect)Dim myXmlReader As System.Xml.XmlReader = objHelperCommand.ExecuteXmlReader()
RunSPReturnXMLReader = myXmlReader - GETTING ERROR HERE
End Function
 
Thanks...

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved