DataSource Controls :: Using Table-valued Parameters?

May 19, 2010

This is my first attempt in using table valued parameters in my stored procedures. Please find the scripts down below. The idea is very simple. I'm trying to insert a new product into Products table and if the product has attributes, I'll insert them into ProductAttributes table which is where I use table-values parameters.

I was able to test the stored procedure manually. It's working fine. So the error must be in the C# code but there's not much to it.

Here's the DAL code in C# that calls the stored procedure:

[Code]....

Just in case you need it, here's what my Product object looks like:

[Code]....
And the ProductAttribute object is even simpler:

[Code]....

Here's the SQL scripts to create the tables, stored procedure and user defined table type:

[Code]....

View 4 Replies


Similar Messages:

Can ObjectDataSource Use Table-valued Parameters

Oct 15, 2010

If an ASP.NET web page uses an ObjectDataSource, can you configure it to use a stored procedure that uses table-value parameters?

User-defined type:

CREATE TYPE [dbo].[integer_list_tbltype] AS TABLE
(
[n] [int] NOT NULL,
PRIMARY KEY CLUSTERED
)

Stored procedure:

CREATE PROCEDURE [dbo].[GeneralReport]
@intList integer_list_tbltype READONLY
AS
BEGIN
SELECT * FROM ...
END

ASP.NET

<asp:ObjectDataSource ID="GeneralDataSource" runat="server"
SelectMethod="GetDataByRange"
TypeName="MyProject.GeneralDataSetTableAdapters.GeneralViewTableAdapter"
>
<SelectParameters>
<asp:Parameter Name="intList" />
</SelectParameters>
</asp:ObjectDataSource>

I've tried hooking into the ObjectDataSource's Selecting event like this:

[code]....

be set for UDT parameters." being thrown

View 2 Replies

Web Forms :: How To Use A Checkbox List And Table Valued Parameters

Sep 29, 2010

I have a checkboxlist that gets all all the items from a look up table. The user is going to go to the list, check certail items and insert the checkboxid, the value (0 or 1), and the userid into a table valued paramater using a stored procedure. I have the user defined table type created but thats about it. Any body out there have any hints.

View 4 Replies

DataSource Controls :: SQL Server Table-valued Function Vs View?

Jul 9, 2010

I would like to know which one is better, table-valued function or View, in terms of perfomance.Earlier I have created view which is performing cross join (which takes time) and 2/3 Left outer join and it's taking time. To reduce execution time I have created table-valued function with parameter to reduce cross join execution time and it returns the same result as view.Just give me an idea about table-valued function and View, in terms of perfomance. Which one is better?

View 1 Replies

DataSource Controls :: Use An ObjectDataSource Update Method With A Table - Valued Parameter?

Oct 13, 2010

I'm trying to figure out if it's possible to use an ObjectDataSource Update method with a table-valued parameter. Here's my ODS:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
DataObjectTypeName="TestProject.MyTestDataTable"
SelectMethod="GetTestData" TypeName="TestProject.BLL.TestBLL"
OldValuesParameterFormatString="original_{0}"
UpdateMethod="UpdateTestData">
<SelectParameters>
<asp:Parameter DefaultValue="65" Name="testId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

I bind this to a GridView but I'm not looking to edit row by row. Instead my GridView has a bunch of TemplateFields with textboxes. I also have a Button that when pressed, invokes the Update method of the ODS. So then the "UpdateTestData" function in my TestBLL is called. This looks like this:

public void UpdateTestData(MyTestDataTable dt)
{
QueriesTableAdapter qta = new QueriesTableAdapter();
qta.UpdateTestData(dt);
}

At run-time in debug, it seems like the object for the signature above is not populated with the data from my GridView.

View 1 Replies

SQL Server :: Using Dynamic SQL Within A Table-valued Function?

Jan 27, 2011

I am trying to develop a function that returns a table. I have written: -

[code]...

I am using SQL Server 2008 V2 Express, but my production database is SQL 2005 so solutions will need to be compatible with that.

View 6 Replies

ADO.NET :: SQL Table Valued Parameter And Linq In Framework 4.0?

Jan 21, 2011

know if the followin is supported in .net framework 4.0?I have a sql stored procedure with one of its parameter as Hierarchy data type( i suppose its a table valued parameter).. trying to drag this stored procedure onto my linq design studio is not being allowed?

View 1 Replies

SQL Server :: To Pass A Table Type Variable To A Table-Valued UDF In SQL Server 2005?

Nov 25, 2010

I need to pass a table type parameter to a user-defined table valued function in SQL Server 2005.How would I do this?

My function name is udf_t_GetSales ( @financialYearMonthsData as table)

The table @financialYearMonthsData has 3 columns ( MonthId int, DisplayText nvarchar(500), CalendarYear int)

View 7 Replies

SQL Server :: What If Multiple Output Parameters And Input Parameters And Also Want A Select Table

Feb 16, 2011

[Code]....

When I want to get the output values its okay but I also want returning a table as a result data.But Datareader has no rows.is it possible if I want a returning query result and multiple output values togather ?I wrote a test above.I can get output values as sqlparameters. But Datareader attached to a Gridview is empty.can you detect whats wrong here and it doesnt return a query result.So stored procedure is not standart or ı am doing something wrong.this doesnt raise any exception.but not returning any data.

[code]....

View 8 Replies

DataSource Controls :: Use Is Null In Query Without Using Parameters For It Or Should Use Parameters For This Field Where Value Is NULL

Jan 21, 2010

here is my code for selectiong some records from db table

string strSql = "select * from mtblNBD where SentTo=@SentTo and InternalStatus Is NULL order by DeadLine desc";
SqlCommand com = new SqlCommand(strSql, con);
com.Parameters.Add("@SentTo", SqlDbType.NVarChar, 50).Value = (string)Session["uname"];

here I am using parameters for SenTo field but not for NULL so it is ok... or should I use parameters for this field where value is NULL , if yes then how can I use parameter for this

View 8 Replies

DataSource Controls :: Add Parameters On Dataadapter?

Jun 23, 2010

How could I add parameters on dataadapter? I tried

[Code]....

But parameters is unknown for dataadapter.

View 4 Replies

DataSource Controls :: SqlDataSource With A Lot Of Parameters?

Sep 4, 2010

I have asked similiar question before where I have two control on the page header says "username" and "gender". User can select both the control or either one and the page will execute searching based on the criteria supplied. So if username supplied

SELECT * FROM [this_table] WHERE username = @username
and if gender supplied
SELECT * FROM [this_table] WHERE gender = @gender
and if both supplied
SELECT * FROM [this_table] WHERE username = @username AND gender = @gender

I know this sounds not very complicated but in my case, I am having like more than 10 controls up there. It is something likeusername, gender, age, date of brith, title, father name, frst name, last name, blur blur blur and it's a lot then I started to lost. if i were to use if else caluse on code-behind and produce query, it would end up writing a lot of if-else and if i use stored procedure (with if-else) then my stored procedure would contains a lot of if-else statement. I am fairly new to this concept and if I'm on the wrong track, please correct me. Is there any better way to save my hair without actually going through each
if-else statement to build the query ?p.s. I'm using GridView and SqlDataSource command to display the result back on .aspx page.

View 2 Replies

DataSource Controls :: Using Parameters For A Listview

Jun 4, 2010

I have webform with a listview control on it that uses 2 date values supplied by the user (via 2 text boxes) to dynamically set date range parameters for the datasource. The user enters two dates and clicks a button that runs the following code that sets the parameters:

[Code]....

This code works the first time the user clicks the button. But if they change the date values and try again, it only returns the result set from the first request. The parameters are not updated to the new values supplied by the user.

View 2 Replies

DataSource Controls :: Can Use If Else In Sqldatasource If Else Parameters

Oct 4, 2010

I am trying to check whether a username exists in my database before inserting the new row & display a message to the user if it does.

On my SqlDataSource my InsertCommand looks like this:

InsertCommand="IF NOT EXISTS (SELECT * FROM Users WHERE UserName = @UserName) BEGIN INSERT [Users] ([UserName], [FirstName], [LastName], [City], [State], [Country], [CompanyName], [Active], [PasswordHash]) VALUES (@UserName, @FirstName, @LastName, @City,
@State, @Country, @CompanyName, @Active, @PasswordHash) END"

This works as expected: If the username is unique, the row is created.

If the username already exists, the row is not added.

The problem is, if the row already exists, the insert is rejected but the user is not notified.

So my question is, is there a way I can notify the user?

Maybe something like: InsertCommand = "If Not Exists (select....) Begin Insert...Else Notify User Somehow End This is a basic database, I'm not using the built-in membership provider nor will be.

View 1 Replies

DataSource Controls :: Inserting Parameters?

Jan 10, 2010

I'm linking a form to sql database, As far as i know for textbox the code will be like this one below in VB:

dashDataSource.InsertParameters.Add("databaseColumName", NameOFTextBox.Text)

But what is the code for a drop down menu for countries list?

View 3 Replies

DataSource Controls :: No Value Given For One Or More Required Parameters?

Apr 13, 2010

I can't see what I've missed

Dim strSQL As String = _
"UPDATE [emailText] SET " & _
"[stdSubjectLine] = @subjLine, [stdBodyText] = @bodyText, " & _

[code]...

View 1 Replies

DataSource Controls :: Select A Record From A Table And Insert Into B Table Using Linq?

Jun 29, 2010

how can i select a record from A table and insert into B table using linq?

View 2 Replies

DataSource Controls :: Way To Retrieve Data From A Table, Modify And Insert It Into Another Table

Jun 13, 2010

Basically i deal with two tables.i have a table T1 of the following format:id company_name i need to read this data and create a table T2 as followsi wrote the following code. it worked fine for retrieving data and modification but fails to insert the modified data into the 2nd table.the error is, it does not recognise the value for @token

ArrayList dynarr=new ArrayList(); // global variable
protected void Button2_Click(object sender, EventArgs e)
{
int row = 1; int i;
string strcmd = null;
string Connection = "Data Source=....";
SqlConnection conn = new SqlConnection(Connection);
string str = "select company_name from T1 where ID=@ID";
[code]...

View 2 Replies

DataSource Controls :: Passing Parameters To ObjectDataSource

Aug 9, 2010

I followd Brian Orrell LINQ tutorial for paging/sorting and created a gridview bound to an ObjectDataSource through a method call which gets data from adatabase. My form includes two buttons with a textbox next to each one of them. I need to be able to populatte th egridview depending on the button that was pressed, I cannot figure out how signal my method which button was pressed.
[Code]....
[URL]

View 1 Replies

DataSource Controls :: Setting Parameters In ListView

Mar 17, 2010

I have a ListView that, among other things, in the EditItemTemplate, has a pair of related DropDownList controls, sort of a parent/child relationship. The selected value of the parent is used as a parameter for the SQL Datasource of the child. Outside of a control such as the ListView, this would be easy and I'd simply set up a ControlParameter for the SQL Datasource and life would be good. Within the DataList things are not quite so simple. My plan is to set the parameter of the child in the Selecting handler of its datasource. I have hard coded some values and this works the way I want it to. My problem is getting the "parent" value. I've got two theories on how to get this:

#1, I've tried instantiating the parent DropDownList but it is either not available at this point in the page life cycle or I just don't know the syntax to get at it from within the Selecting handler.

#2, I'm thinking I may have to grab the value from the underlying data for the ListViewRow that I am editing, but again, I do not know the object model well enough to get at those values.

Below is a code sample for option #1. As stated, setting the parameter works, but getting the value of the DropDownList does not.

View 5 Replies

DataSource Controls :: Sql Parameters - Not Listed In Dropdown

Oct 12, 2010

All control are not listed in dropdown when selecting a control for adding parameter to update query.

View 1 Replies

DataSource Controls :: How To LinqDataSource Date Parameters

Jun 15, 2010

I need to retrieve data using a date as an input parameter. I created a WhereParameter and passed in a date value that I know to exist in the database, but no data is returned. Heres my code

[Code]....

Ive passed in '02/06/2010' as the date, in the database, the Startdate column has several values of '2010-06-02 13:08:50.503' so I guess its not being found because of the time part. Whats the best way to make sure that I retrieve the correct data ? Im not concerned about the time at all, I just need all rows for 02/06/2010.

View 3 Replies

DataSource Controls :: Getting Sql Functions Parameters Into The C# Code

Apr 30, 2010

getting the Parameters declared in an sql function in the C# code. We can actually get the parameters from a Stored Procedure by giving SqlCommandBuilder.DeriveParameters

Similarly is there any way to get the Parameters from the SQL Function.

View 2 Replies

DataSource Controls :: Combining Two Parameters To One Column?

Jan 21, 2010

Is it possible in SqlDatasource Update command to combine two parameters to make a third?

[Code]....

this is what I need to do Combine First and Last names with a space between.

View 4 Replies

DataSource Controls :: Using HttpContext Inline With Parameters

Jul 3, 2010

I'm attempting to use the following parameter value in my data source:

[code]

<asp:Parameter Name="IPAddress" DefaultValue='<%= HttpContext.Current.Request.UserHostAddress %>' />

[/code]

But the string literal "<%= HttpContext.Current.Request.UserHostAddress %>" is being sent to my stored procedure.

View 2 Replies







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