Showing posts with label component. Show all posts
Showing posts with label component. Show all posts

Monday, March 12, 2012

How to Set Start Index in a Data Control which is attahced to a Data Component

Hello All,

I have a SQLDataSource "sdsX" which has four records. There is a DataList "dlX" which is binded to this SQLDataSource "sdsX". Now I want that my datalist "dlX" take third record of "sdsX" as its first element. Is there any property which can be used.

Thanks

Hi ShailAtlas,

Base on my understanding, you want to move the third row to first row in DataList. For example:

Here is a DataList rendered likes below:

----------

1 | name1 |

----------

2 | name2 |

----------

3 | name3 |

----------

4 | name4 |

----------

You want to render it likes below without any change of datasource.

----------

3 | name3 |

----------

1 | name1 |

----------

2 | name2 |

----------

4 | name4 |

----------

If I have misunderstood your concern, please feel free to let me know.

DataList doesn't have property for this special request. If you want to implement it, you should add your own code in DataList_PreRender event handler. Here is the sample code:

int i = 0;

protectedvoid Page_Load(object sender,EventArgs e)

{

DataList1.DataBind();

}

protectedvoid Button1_Click(object sender,EventArgs e)

{

i =int.Parse(TextBox1.Text);

}

protectedvoid DataList1_PreRender(object sender,EventArgs e)

{

if (i != 0)

{

int j = i - 1;

string backupid = ((Label)DataList1.Items[j].Controls[1]).Text;

string backupname = ((Label)DataList1.Items[j].Controls[3]).Text;

for (; j > 0; j--)

{

((Label)DataList1.Items[j].Controls[1]).Text = ((Label)DataList1.Items[j-1].Controls[1]).Text;

((Label)DataList1.Items[j].Controls[3]).Text = ((Label)DataList1.Items[j-1].Controls[3]).Text;

}

((Label)DataList1.Items[0].Controls[1]).Text = backupid;

((Label)DataList1.Items[0].Controls[3]).Text = backupname;

}

}

When you input 3 in TextBox1 and then press Button1. DataList begin to render with the special order.

|||

Hello Ben,

Lets understand like this.I have a SQLDataSource which has 4 records. Now I have 2 datalist say DataListX and DataListY.

I want that DataListX should show record number 1 & 2, and DataListY should show records 3 & 4

SQLDataSource has records like this

----------

1 | name1 |

----------

2 | name2 |

----------

3 | name3 |

----------

4 | name4 |

----------

Now DataListX will show like this

----------

1 | name1 |

----------

2 | name2 |

And DataListY should be like this

----------

3 | name3 |

----------

4 | name4 |

Intention is that I do not want to use 2 SQLDataSource for same type of records

Thanks for your Reply

Shail

How to set SQLCommand timeout for SqlDataSource for ASP.NET 2.0?

With VS2005, there is a new component SqlDataSource,

<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>

Then you can assign SP and bind datasource to a get data for this component in .NET code:

SqlDataSource1.SelectCommand = "spName"
SqlDataSource1.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
SqlDataSource1.ConnectionString = Comm.connString

There is no way to set sqlcommand timeout for this stored procedure like SqlClient.SqlCommand. How can I do this?

Inside the SqlDataSource1_Selecting event, you get access to the sqlcommand object via e.command. You can set the commandtimeout on it there, like:

e.Command.CommandTimeout=300

|||

Thanks for your reply. But when is the event Selecting fired? Is it fired automatically when binding to data source?

|||

Hi KentZhou,

The sqldatasource.selecting event happends right before your perform a data retrieval opteration(where you execute your select command).You can refer to the msdn explaination:

msdn:

Occurs before a data retrieval operation.

Handle theSelecting event to perform additional initialization operations that are specific to your application, to validate the values of parameters, or to change the parameter values before theSqlDataSource control performs the select operation. The select arguments are available from theSqlDataSourceSelectingEventArgs object that is associated with the event.

Hope my suggestion helps

|||

The short answer is "Yes".

It fires any time that you do a databind.

The long answer as described above, it actually happens any time that the SqlDatasource is about to go and execute your select command. This is normally done through a databinding operation (Either implied or programmatically triggered), however it can also be triggered if you call the select method on the SqlDatasource directly.

Friday, March 9, 2012

How to set sheetname on an Excel destination component ?

Hello, I am trying to create a simple package programmatically. I am following the examples in the BOL, and from some advice here. I am getting stuck at creating an Excel Destination and setting its sheetname. Everything works fine, including setting the output Excel filename. I get a runtime exception when I try to set the sheetname via SetComponentProperty. Is there another way, or am I doing something wrong? Thanks for any info you may have.

' Create and configure an OLE DB destination.

Dim conDest As ConnectionManager = package.Connections.Add("Excel")

conDest.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _

Dts.Variables("User::gsExcelFile").Value.ToString & ";Extended Properties=""Excel 8.0;HDR=YES"""

conDest.Name = "Excel File"

conDest.Description = "Excel File"

Dim destination As IDTSComponentMetaData90 = dataFlowTask.ComponentMetaDataCollection.New

destination.ComponentClassID = "DTSAdapter.ExcelDestination"

' Create the design-time instance of the destination.

Dim destDesignTime As CManagedComponentWrapper = destination.Instantiate

' The ProvideComponentProperties method creates a default input.

destDesignTime.ProvideComponentProperties()

destination.RuntimeConnectionCollection(0).ConnectionManager = DtsConvert.ToConnectionManager90(conDest)

destDesignTime.SetComponentProperty("AccessMode", 0)

'runtime Exception here

destDesignTime.SetComponentProperty("OpenRowSet", "functions")

Guess time!

If you post the error details, it normally helps. I'll guess at error HResult 0xC0204006, some notes - http://wiki.sqlis.com/default.aspx/SQLISWiki/0xC0204006.html

Properties are case sensitive, and it is called OpenRowset not OpenRowSet.

How did i do?

|||Yep, the case sensitivity was it. Thanks!

How to set sheetname on an Excel destination component ?

Hello, I am trying to create a simple package programmatically. I am following the examples in the BOL, and from some advice here. I am getting stuck at creating an Excel Destination and setting its sheetname. Everything works fine, including setting the output Excel filename. I get a runtime exception when I try to set the sheetname via SetComponentProperty. Is there another way, or am I doing something wrong? Thanks for any info you may have.

' Create and configure an OLE DB destination.

Dim conDest As ConnectionManager = package.Connections.Add("Excel")

conDest.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _

Dts.Variables("User::gsExcelFile").Value.ToString & ";Extended Properties=""Excel 8.0;HDR=YES"""

conDest.Name = "Excel File"

conDest.Description = "Excel File"

Dim destination As IDTSComponentMetaData90 = dataFlowTask.ComponentMetaDataCollection.New

destination.ComponentClassID = "DTSAdapter.ExcelDestination"

' Create the design-time instance of the destination.

Dim destDesignTime As CManagedComponentWrapper = destination.Instantiate

' The ProvideComponentProperties method creates a default input.

destDesignTime.ProvideComponentProperties()

destination.RuntimeConnectionCollection(0).ConnectionManager = DtsConvert.ToConnectionManager90(conDest)

destDesignTime.SetComponentProperty("AccessMode", 0)

'runtime Exception here

destDesignTime.SetComponentProperty("OpenRowSet", "functions")

Guess time!

If you post the error details, it normally helps. I'll guess at error HResult 0xC0204006, some notes - http://wiki.sqlis.com/default.aspx/SQLISWiki/0xC0204006.html

Properties are case sensitive, and it is called OpenRowset not OpenRowSet.

How did i do?

|||Yep, the case sensitivity was it. Thanks!

How to set null value for a smalldatetime inside a Script Component task?

how the hell you allocate a null value for a smalldatetime sql field?

Now, I'm putting a false date because of I'm stuck with this f.. and then I do an update:

.Parameters("@.FecEnajenacion").Value = "1999-01-01"

error:

.Parameters("@.FecEnajenacion").Value = vbNull

.Parameters("@.FecEnajenacion").Value = Null

.Parameters("@.FecEnajenacion").Value = SqlDbType.?

Try

Parameters("@.FecEnajenacion").Value = Nothing

-Jamie

|||

hi jamie,

Well, it doesn't works because of my code wait any value:

Public Overrides Sub PreExecute()

sqlCmd = New SqlCommand(sSql, sqlConn)

sqlParam = New SqlParameter("@.FecEnajenacion", SqlDbType.SmallDateTime)

sqlCmd.Parameters.Add(sqlParam)

....

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

.....

With Sqlcmd

If dFecha2 = "0000/00/00" Then

.Parameters("@.FecEnajenacion").Value = Nothing

Else

.Parameters("@.FecEnajenacion").Value = dFecha2

End If

.ExecuteNonQuery()

End With

End Sub

Prepared statement '(@.Ejercicio smallint,@.NIFPerc char(9),@.NIFRep char(9),@.Nombre va' expects parameter @.FecEnajenacion, which was not supplied.

|||enric,

the DBNull data type must be used when setting the parameter value property to null.

i recommend that you post this question to the ADO.NET forum for further assistance.|||thank you

How To Set Multiple ReadOnlyVariables in Script Component in Integration Services 2005

Hello!

I'ave got a problem of setting more than one Variable in ReadOnlyVariables Property of ScriptComponent...I provide comma separated list of names ( As described in the help ) byt VS Studio Editor can not be opoened claiming that there is no a variablle with such a name...Looks like it doesn't treat the list as a collection of names...

Please help.

Vladimir

Make sure there are no spaces in the list.

Var1,Var2,Var3

This will not work:

Var1, Var2, Var3

Also note that variable names are case sensitive.|||Triple-check your spelling and the scope your variables are defined in. I got the error just this morning and it was a spelling problem.
|||

Thanks for your response...

I verified the spelling got rid of spaces...but result is the same

It is interesting thing.. I have only two variables: One is set on a package level and another is on the Data Flow Task level...

When I set one of them in ReadonlyVariables and another in ReadandWriteVariables it allows me to open VS for Applications. If I move both to the same location ( ReadonLy or ReadAnd Write with comma separation and no spaces ) it issues the message I described...

I tried specifying the namespaces for the variables, but with no Luck...

Not usre what to do...

Any ideas will be greately appreciated...

Thanks,

Vladimir

|||What version of SSIS are you using?

RTM? SP1? SP2?