get/set SourceColumn values manually?

  • Thread starter Thread starter R Reyes
  • Start date Start date
R

R Reyes

Hi,

Is there a way to get/set (or override) SqlParameter.SourceColumn values
manually?

Code example:
// create DeleteCommand by SourceColumn
strSQL = "DELETE FROM [MyTable] WHERE (ID=@ID)";
using (sqlData.DeleteCommand = new SqlCommand(strSQL, sqlConn))
{
sqlParam = sqlData.DeleteCommand.Parameters.Add("@ID", SqlDbType.Int);
sqlParam.SourceColumn = "ID";
}

// Get/Set parameter values manually
GetSetParameterValuesManually();

I want to find out the values of @ID in the GetSetParameterValuesManually()
function, row by row, so that I can delete corresponding data in OTHER tables
that use the ID column as the link.

I suppose if there was a way to DELETE from multiple tables using IDs to
link each other it would work, but I don't know if there is a way to do that.

Please help and thanks for your time.
 
R Reyes,

Have you looked into creating foreign key relationships in the database?
I know in SQL Server, at least, there is an option to cascade deletes, so
that things that are related to the record being deleted will be deleted as
well.

The SourceColumn parameter is not read-only, so you can set the
SourceColumn parameter to whatever you wish.

If you have the DataSet that you are using to get the values from, you
can just use the SourceColumn property to get the value that will be used.
If you don't have access to the data set, there isn't anything you can do.
 
"If you have the DataSet that you are using to get the values from, you can
just use the SourceColumn property to get the value that will be used. If you
don't have access to the data set, there isn't anything you can do."

This might work. I'll change the values of the data set BEFORE getting the
sourcecolumn values instead of after. Thanks

Nicholas Paldino said:
R Reyes,

Have you looked into creating foreign key relationships in the database?
I know in SQL Server, at least, there is an option to cascade deletes, so
that things that are related to the record being deleted will be deleted as
well.

The SourceColumn parameter is not read-only, so you can set the
SourceColumn parameter to whatever you wish.

If you have the DataSet that you are using to get the values from, you
can just use the SourceColumn property to get the value that will be used.
If you don't have access to the data set, there isn't anything you can do.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

R Reyes said:
Hi,

Is there a way to get/set (or override) SqlParameter.SourceColumn values
manually?

Code example:
// create DeleteCommand by SourceColumn
strSQL = "DELETE FROM [MyTable] WHERE (ID=@ID)";
using (sqlData.DeleteCommand = new SqlCommand(strSQL, sqlConn))
{
sqlParam = sqlData.DeleteCommand.Parameters.Add("@ID", SqlDbType.Int);
sqlParam.SourceColumn = "ID";
}

// Get/Set parameter values manually
GetSetParameterValuesManually();

I want to find out the values of @ID in the
GetSetParameterValuesManually()
function, row by row, so that I can delete corresponding data in OTHER
tables
that use the ID column as the link.

I suppose if there was a way to DELETE from multiple tables using IDs to
link each other it would work, but I don't know if there is a way to do
that.

Please help and thanks for your time.
 
Back
Top