Showing posts with label wizard. Show all posts
Showing posts with label wizard. Show all posts

Friday, March 30, 2012

How to value parameters for sqldatasource

I set up a sqldatasource based on a stored procedure which takes one parameter. The sqldatasrouce wizard generates the following code for the parameter below. The question is how do I value the DeptID parameter on the load of the form. I tried the following code in the load of the page, but get a null reference error:

Me.SqlDataSource1.InsertParameters("DeptID").DefaultValue = Session("DeptID")

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:FDConn %>"
SelectCommand="GetTruckStatus" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="DeptID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<radG:RadGrid ID="RadGrid1" runat="server">
</radG:RadGrid>

You've set the value of an InsertParameter, but you are performing a Select, not an Insert. Anyway, the SqlDataSource offers a number of different parameter types. One of them is an <asp:SessionParameter>. Use that instead of the generic<asp:Parameter> that you are currently using. You can reconfigure the SqlDataSource to generate it automatically. Click the WHERE button when applying the Select Statement, and in the Source dropdown, choose Session.

|||

Mike,
Thanks for the information. I went back into the configure the sqldatasrouce, but if you chose to use a stored procedure, the button for selecting "Where" is grayed out. I assumed that since the code was generated from vb and from the stored procedure I selected, vb would know the type of parameter it had to generate.


Regards,
Tom

|||

Mike,

I went back into the code and used the "SelectParameter" type and all worked well. Thanks for pointing me in the right direction.

Tom

Friday, March 23, 2012

How to use tableadapter wizard with vendor specific keywords?

Hi. I really like the new tableadapter wizards and how they can speed up development. However, I'm running into a problem I need help with. I am using the table adapter against DB2 and there are special keywords that the designer isn't allowing.

i.e.
Select field1, field2
from table
for fetch only with ur;

When I enter this into the query wizard and then move off the SQL pane to another pane, the wizard quotes the sql so it looks like so:
Select field1, field2
from table
FOR "fetch" "only" "with" ur;

Hence my predicament. When I try to run this or press the ok button to save the query, it won't run because the odbc driver isn't expecting fetch, only, and with to be in double quotes. Is this a known issue or is there some key token to indicate that the keywords should be left alone.

In case anyone is wondering why this would be a problem, in DB2 the keywords above indicate to not use record locking on a table. In an enterprise situation with potentially thousands of users, record locking is not acceptable. In order for our enterprise to use the new enhancements made in VS 2005 to the tableadapter, we need a way around what the designer is doing.

Please advise.To the moderator of this forum:
This post was moved from the C# IDE forum by someone who didn't understand what I was asking them. I've reposted it with clearer meaning (hopefully). Please remove this post from this forum. It doesn't belong here. I would delete it if I could, but I don't seem to have the button to do it anymore.

Thanks,
Jonsql