Showing posts with label sqlcommand. Show all posts
Showing posts with label sqlcommand. Show all posts

Friday, March 23, 2012

Passing DDL value to bit field in SQL

I have a DDL with two values: 0 and 1. When I use

sqlcommand.Parameters.Add(New SqlParameter("@.fld", SqlDbType.Bit, 1))
sqlcommandl.Parameters("@.fld").Value = System.Boolean.Parse(DropDownList1.SelectedValue)

or

sqlcommand.Parameters.Add(New SqlParameter("@.fld", SqlDbType.Bit, 1))
sqlcommandl.Parameters("@.fld").Value = System.Convert.ToBoolean(DropDownList1.SelectedValue)

to insert the selected value in a sql2k database BIT field I am given this error:

System.FormatException: String was not recognized as a valid Boolean.

How can I solve this problem?


// C# but you should get the idea
bool trueFalse = false;
if( DropDownList1.SelectedValue.Value.Equals("1") ){
trueFalse = true;
}
sqlcommandl.Parameters("@.fld").Value = trueFalse;

Saturday, February 25, 2012

Pass a variable to a DataReader in a DataFlow task

How can I pass a variable to a DataReader in a DataFlow task?

My SqlCommand for the DataReader is:
SELECT CustName, CustCode FROM Customers WHERE CustCode = '?'

The DataFlow task is nested in a ForEach loop. I confirmed that the variable is changing with each loop by using a ScriptTaks and a message box. However, the DataReader SqlCommand does not seem to be updating.

You need to put the query into a variable, let's say @.myquery.

@.myquery would use an expression to make it dynamic on each iteration. Then you have to assign @.myquery variable to the data reader via expression. For doing that, go to the control flow; select the data flow task go to properties; select expression and add an expression to SQLCommand proepty. The proeprty should be just: @.myquery.

|||

This article by Jamie Thomson gave me more detail to accomplish what Rafael described:

http://blogs.conchango.com/jamiethomson/archive/2005/12/09/SSIS_3A00_-Using-dynamic-SQL-in-an-OLE-DB-Source-component.aspx

Note: the SQLCommand property of the DataReader gets renamed to [Name of DataReader Source]

|||

Well,

That article applies for OLE DB source component; for a data reader is slightly different.

Good that it worked for you!