Showing posts with label load. Show all posts
Showing posts with label load. Show all posts

Tuesday, March 27, 2012

Change Image using parameter

I need to change the logo on my reports according to a parameter that I pass from VB.NET.

What is the best way to load the image into the report?

I have attempted to use a dataset:

I created a logo field in my dataset
I loaded the correct image in VB.NET
I then assigned the 'logo' field in the dataset to this image

My problem is that I don't know what the data type of the logo field should be - I have created the dataset manually and the images are not in a database.

This is my code:

'Load image into ByteArray
Dim fs As New System.IO.FileStream("C:\temp\test.jpg", IO.FileMode.Open)
Dim nBytes As Integer = fs.Length
Dim ByteArray(nBytes) As Byte
Dim nBytesRead As Integer = fs.Read(ByteArray, 0, nBytes)
fs.Read(ByteArray, 0, Convert.ToInt32(fs.Length.ToString(), 10) - 1)

'Set logo field to this image
Dim tbl As New mySchemas.myDataTable
Dim rw As DataRow = tbl.NewRow
rw("logo") = ByteArray 'AN ERROR OCCURS ON THIS LINE
tbl.Rows.Add(rw)
Dim ds As New DataSet
ds.Tables.Add(tbl)

Is this the best way to do load an image into crystal? If so what should the datatype of the logo field be in the dataset? I tried Byte but that did not work.

Thanks for any help
ElaineElaine,
I'll preface this by saying: I don't use CR10, and don't use .NET with CR.
From your code you are declaring a row object to hold the picture.
Shouldn't you be using a "field" object, or whatever the .NET equivalent is?
Field type should be OLE Object/BLOB(BinaryLargeOBject)/BitStream or similar.

Dave|||Thanks for your reply Dave. All sorted now.

The data type I needed turned out to be 'hexbinary'
Incase anyone has the same problem this is the solution:

Dim data As New DataSet()
Dim row As DataRow

data.Tables.Add("Images")
data.Tables(0).Columns.Add("img", System.Type.GetType("System.Byte[]"))

Dim fs As New FileStream("C:\test.jpg", FileMode.Open)
Dim br As New BinaryReader(fs)

row = data.Tables(0).NewRow()
row(0) = br.ReadBytes(br.BaseStream.Length)
data.Tables(0).Rows.Add(row)

br.close
fs.close

br = Nothing
fs = Nothing

' CrystalReport1 is a strongly typed report created in Visual Studio.
Dim cr As New CrystalReport1()
cr.SetDataSource(data)
CrystalReportViewer1.ReportSource = cr|||Are you using the version of crystal reports that came with visual net??
I create the typed dataset with a field hexBinary and load the pictur there but how can I put that picture in the report it shows as a number and no image apearssql

Monday, March 19, 2012

Change Data Capture

Again, looking for the best way to do this with SSIS.

I have a source table and I'd like to load it to a database daily, capturing what changed.

This is not a dimentional table but a fact table.

So, what I;d need to do for each record is to see if the record already exists (using business key) and if it does - compare some of the data fields and of there are changes - register it somehow and if not changes ignore.

Right now, the only two ways I see to do it with SSIS:

- Use Slowly Chaging Dimentions transformation

- Use Lookup and customize SQL, adding something like: WHERE key = ? and (field1 <> ? or field2 <> ?...)

I was wondering of there an easy way.

Dima.

Use checksums... I have something about that on my blog, you can download the component on www.sqlis.com...|||

this is not bad! not bad at all...

and it fits my case, since I have around 80 columns to check.

I wish they extened data destination column mapping to do this. If they added an Option column on the mapping screen with things like: "Key", "Track Changes", "Overwrite" - this would be so powerfull tool.

Saturday, February 25, 2012

Century date conversions

Hi,
I'm trying to load date fields into SQLServer using DTS, but the
format of the raw data is the number of days since 1 Jan 1900. How do
I convert this to a useful format, is there a standard conversion
routine?

Thanks
Timtim.philbrook@.cazenove.com (Helsop) wrote in message news:<1609a822.0408180233.9fbed33@.posting.google.com>...
> Hi,
> I'm trying to load date fields into SQLServer using DTS, but the
> format of the raw data is the number of days since 1 Jan 1900. How do
> I convert this to a useful format, is there a standard conversion
> routine?
> Thanks
> Tim

There are (at least) two possible solutions. First, load the data into
a staging table and clean it up with TSQL, before an INSERT into the
final table:

insert into dbo.Destination
(col1, datetime_column, ...)
select col1, dateadd(dd, numdays_column, '19000101'), ...
from dbo.Staging

Alternatively, if you want to do the transformation in DTS, then you
could use the VBScript DateAdd() function in an ActiveX column
transformation to achieve the same thing.

Simon|||--> use DATEADD(dd,@.OffsetDays,'1 Jan 1900')

DECLARE @.OffsetDays BIGINT
SET @.OffSetDays = 38217
select DATEADD(dd,@.OffsetDays,'1 Jan 1900')

Tx

Tuesday, February 14, 2012

catch sql command if value doesnt exist

I have a sql command that is loaded on page load that collects information based on the query string. The query string is a random group of numbers and letters. How do I catch it and direct to an error page if the query can not be found in the database?

Thanks!

if you are trying to get some parameters from the querystring then you can use

dim queryvariable as string =request.querystring("variable")

try

dim sqlquery as string

sqlquery="SELECT column_Name from Table_name where variable= "& queryvariable

//use this sqlquery to check whether it returns some rows or not

catch

response.redirect("pageNotFound.aspx")

end try

|||

I'm pretty sure i did all that.

in page load i'm doing

getUserInfo(Request.QueryString["uid"]);

then the method

protected void getUserInfo(string userid) {string selectCmd ="SELECT * from users WHERE ID = @.id";string strConnection = ConfigurationManager.ConnectionStrings["TimeAccountingConnectionString"].ConnectionString; SqlConnection myConnection =new SqlConnection(strConnection); SqlCommand myCommand =new SqlCommand(selectCmd, myConnection); myCommand.Parameters.Add(new SqlParameter("@.id", SqlDbType.VarChar, 10)); myCommand.Parameters["@.id"].Value = userid;try { myConnection.Open(); SqlDataReader datareader = myCommand.ExecuteReader();while (datareader.Read()) { lblFirstName.Text = datareader["firstname"].ToString(); lblLastName.Text = datareader["lastname"].ToString(); lblTeam.Text = datareader["team"].ToString(); lblOffice.Text = datareader["office"].ToString(); } datareader.Close(); myConnection.Close(); }catch { Response.Redirect("~/error.aspx"); }
|||

any ideas?

|||

In your code you aren't checking if the datareader actually contains any data or not, so if no records are being returned nothing happens. 1 simple way to do it is:

1. Declare a boolean variable at the top initialized to False: boolean bolUserFound = False

2. Inside the while loop set the value to true: bolUserFound = True

3. After you close the connection evaluate the variable and if it's still false you know no records were found and you need to redirect to your error page:

if (bolUserFound = False) {

Response.Redirect("~/error.aspx");

}

|||

perfect!

Exactly what i needed...