Getting Results From Sqldatasource In Codebehind

Dec 2, 2005

(New to ASP.net 2.0 and database connection)

 

I have created an sqldatasource on the aspx page, which works fine, but how do I get the results from it in the codebehind?

View 2 Replies


ADVERTISEMENT

Sqldatasource.. Codebehind.. Help

May 13, 2008

hi to all,i am kinda crazy now... i have this problem regarding codebehind codes... i am kinda still a beginner...can you please give me an example of codebehind codes in which selectcommand (and other commands) in sqldatasource to be written in aspx.vb not on aspx..on how to execute it and so as its parameters...i know that those commands are easy to configure on aspx page... but there some reasons why i need to put it in aspx.vb page... so is there any way...? is my problem clear?hoping for a reply asap.. thank you... 

View 4 Replies View Related

SQLDataSource In Codebehind??

Apr 17, 2006

I am trying to use the SQLDataSource from the codebehind.  However, I have a problem accessting the ConnectionString.I declare my connection string in my web.config file, and I declare this as:Dim DBConn As New SqlConnection(ConfigurationManager.ConnectionStrings("DbConnString").ConnectionString)My problem arises though when I get to the SQLDataSource.  How can I reference DBConn via the SQLDataSource.ConnectionString?Karls

View 1 Replies View Related

Execute SQLDataSource From Codebehind

Mar 4, 2008

Hi,
I have a SQLDataSource, button, textbox, and label.  I  take the text from the textbox, count it's occurance in the database, then assign the number to the label.  The code works but I would like to provide a button that will execute/invoke the SQLDataSource.
I have this in the click event for the button:
Me.label1.Text = SqlDataSource1.Select(DataSourceSelectArguments.Empty)
How do I execute a SQLDataSource from the code-behind for the button click event?
Thanks.

View 2 Replies View Related

How Get Data From SqlDataSource Into CodeBehind?

Apr 6, 2008

Hello...Can someone help me?I´m getting info of a product via sqldatasource in this way:<asp:SqlDataSource ID="myData" runat="server" ConnectionString="..." SelectCommand="spGetProduct" SelectCommandType="StoredProcedure">                       <SelectParameters>      <asp:QueryStringParameter Name="Id" QueryStringField="Id" Type="String" />   </SelectParameters></asp:SqlDataSource>In my ASPX page I get the data in this way:<asp:Repeater ID="repProduct" runat="server" DataSourceID="myData">   <ItemTemplate>      <p><%# Eval ( "ProductName") %></p>   </ItemTemplate></asp:Repeater> My problem is in my code behind because I need some data from this DataSource.For example, I want the Product Name as the page title. So the question is how I get something like this in my code behind:protected void Page_Load ( object sender, EventArgs e ){    this.Page.Title = Eval ( "ProductName") ;}Thanks! 

View 2 Replies View Related

Can I Get Data From Sqldatasource With Codebehind?

Apr 13, 2008

Hi, I don't know if i's a silly question.
Now I want to get data from sqldatasource by only write some code,I don't know without creat some data control components if it can be true?
If it can do,how can I write the codes?
Especially I don't know how to write the code witch can "read" data.

View 3 Replies View Related

Check If SqlDataSource Is Empty In CodeBehind

Feb 10, 2006

This is probably an easy one.
What is best way to determine if a SqlDataSource is empty (i.e. the query produced no results) in the CodeBehind?
I'm using this:
if (SqlDataSource1.SelectCommand.Contains(String.Empty))
{
      //Add code for scenario here.
}
It seems to work, but something just doesn't feel right about it for some reason.
Thanks

View 2 Replies View Related

Error Inserting UserId In Codebehind Using SqlDataSource.insert()

Feb 9, 2006

I have a database with columnsuserOwnListsuserID uniqueidentifieruserName nvarchar100userList nvrachar100createdDateI
have created successfully a gridview controller to edit these values in
database. The Gridview data is populated by SqlDataSource.I
have also created a EmptyDataTemplate  and created a form into it.
There is only one textBox and submit button to create the First entry
to userOwnLists -table.Now I collect the value from EmptyDataTemplate textbox with id userList1 and create a codebehind logic for the submitbutton.protected void Button2_Click(object sender, EventArgs e)    {        TextBox listName = (TextBox)this.FindControl("listName1", GridView1.Controls);SqlDataSource1.InsertParameters["userId"].DefaultValue = Membership.GetUser().ProviderUserKey;        SqlDataSource1.InsertParameters["userName"].DefaultValue = Membership.GetUser().UserName.ToString();        SqlDataSource1.InsertParameters["listName"].DefaultValue = listName.Text;        SqlDataSource1.InsertParameters["createdDate"].DefaultValue = DateTime.Now.ToString();        SqlDataSource1.Insert();    }The problem is now that I get error: Exception Details: System.Data.SqlClient.SqlException:
Implicit conversion from data type sql_variant to uniqueidentifier is
not allowed. Use the CONVERT function to run this query.OK.  So I Googled a bit and found this:http://scottonwriting.net/sowblog/posts/4690.aspxMy Question is: How do I convert userId so I can insert it to database successfully?This does not work:String userId = Membership.GetUser().ProviderUserKey.ToString();        SqlDataSource1.InsertParameters["userId"].DefaultValue = Convert.ToString(userId);

View 2 Replies View Related

VB.NET Codebehind Code To Update SQL Server 2005 Using SQLDataSource Control?

Jul 20, 2007

Hi, I am a newbie in using ASP.NET 2.0 and ADO.NET.  I wrote a hangman game and want to record statistics at the end of each game.  I will create and update records in the database for each authenticated user as well as a record for the Anonymous, unauthenticated user.  After a win or loss has occurred, I want to programmatically use the SQLDataSource control to increment the statistics counters for the appropriate record in the database (note I don't want to show anything or get user input for this function).
I need a VB.NET codebehind example that will show me how I should set up the parameters and update the appropriate record in the database.  Below is my code.  What happens now is that the program chugs along happily (no errors), but the database record does not actually get updated.  I have done many searches on this forum and on the general Internet for programmatic examples of an update sequence of code.  If there is a tutorial for this online or a book, I'm happy to check it out.
Any help will be greatly appreciated.
Lambanlaa
CODE - Hangman.aspx.vb
1        Protected Sub UpdateStats()2            Dim playeridString As String3            Dim gamesplayedInteger, gameswonInteger, _4                easygamesplayedInteger, easygameswonInteger, _5                mediumgamesplayedInteger, mediumgameswonInteger, _6                hardgamesplayedInteger, hardgameswonInteger As Int327    8            ' determine whether player is named or anonymous9            If User.Identity.IsAuthenticated Then10               Profile.Item("hangmanplayeridString") = User.Identity.Name11           Else12               Profile.Item("hangmanplayeridString") = "Anonymous"13           End If14   15           playeridString = Profile.Item("hangmanplayeridString")16   17           ' look up record in stats database18           Dim hangmanstatsDataView As System.Data.DataView = CType(statsSqlDataSource.Select(DataSourceSelectArguments.Empty), System.Data.DataView)19   20           gamesplayedInteger = 021           gameswonInteger = 022           easygamesplayedInteger = 023           easygameswonInteger = 024           mediumgamesplayedInteger = 025           mediumgameswonInteger = 026           hardgamesplayedInteger = 027           hardgameswonInteger = 028   29           If hangmanstatsDataView.Table.Rows.Count = 0 Then30   31               '   then create record with 0 values32               statsSqlDataSource.InsertParameters.Clear() ' don't really know what Clear does33               statsSqlDataSource.InsertParameters("playerid").DefaultValue = playeridString34               statsSqlDataSource.InsertParameters("GamesPlayed").DefaultValue = gamesplayedInteger35               statsSqlDataSource.InsertParameters("GamesWon").DefaultValue = gameswonInteger36               statsSqlDataSource.InsertParameters("EasyGamesPlayed").DefaultValue = easygamesplayedInteger37               statsSqlDataSource.InsertParameters("EasyGamesWon").DefaultValue = easygameswonInteger38               statsSqlDataSource.InsertParameters("MediumGamesPlayed").DefaultValue = mediumgamesplayedInteger39               statsSqlDataSource.InsertParameters("MediumGamesWon").DefaultValue = mediumgameswonInteger40               statsSqlDataSource.InsertParameters("HardGamesPlayed").DefaultValue = hardgamesplayedInteger41               statsSqlDataSource.InsertParameters("HardGamesWon").DefaultValue = hardgameswonInteger42   43               statsSqlDataSource.Insert()44           End If45   46           ' reread the record to get current values47           hangmanstatsDataView = CType(statsSqlDataSource.Select(DataSourceSelectArguments.Empty), System.Data.DataView)48           Dim hangmanstatsDataRow As System.Data.DataRow = hangmanstatsDataView.Table.Rows.Item(0)49   50           ' set temp variables to database values51           gamesplayedInteger = hangmanstatsDataRow("GamesPlayed")52           gameswonInteger = hangmanstatsDataRow("GamesWon")53           easygamesplayedInteger = hangmanstatsDataRow("EasyGamesPlayed")54           easygameswonInteger = hangmanstatsDataRow("EasyGamesWon")55           mediumgamesplayedInteger = hangmanstatsDataRow("MediumGamesPlayed")56           mediumgameswonInteger = hangmanstatsDataRow("MediumGamesWon")57           hardgamesplayedInteger = hangmanstatsDataRow("HardGamesPlayed")58           hardgameswonInteger = hangmanstatsDataRow("HardGamesWon")59   60           ' update stats record61           'statsSqlDataSource.UpdateParameters.Clear()62           'statsSqlDataSource.UpdateParameters("playerid").DefaultValue = playeridString63   64           If Profile.Item("hangmanwinorloseString") = "win" Then65   66               statsSqlDataSource.UpdateParameters("GamesPlayed").DefaultValue = gamesplayedInteger + 167               statsSqlDataSource.UpdateParameters("GamesWon").DefaultValue = gameswonInteger + 168               Select Case Profile.Item("hangmandifficultyInteger")69                   Case 170                       statsSqlDataSource.UpdateParameters("EasyGamesPlayed").DefaultValue = easygamesplayedInteger + 171                       statsSqlDataSource.UpdateParameters("EasyGamesWon").DefaultValue = easygameswonInteger + 172                   Case 273                       statsSqlDataSource.UpdateParameters("MediumGamesPlayed").DefaultValue = mediumgamesplayedInteger + 174                       statsSqlDataSource.UpdateParameters("MediumGamesWon").DefaultValue = mediumgameswonInteger + 175                   Case 376                       statsSqlDataSource.UpdateParameters("HardGamesPlayed").DefaultValue = hardgamesplayedInteger + 177                       statsSqlDataSource.UpdateParameters("HardGamesWon").DefaultValue = hardgameswonInteger + 178               End Select79   80   81           ElseIf Profile.Item("hangmanwinorloseString") = "lose" Then82   83               statsSqlDataSource.UpdateParameters("GamesPlayed").DefaultValue = gamesplayedInteger + 184               Select Case Profile.Item("hangmandifficultyInteger")85                   Case 186                       statsSqlDataSource.UpdateParameters("EasyGamesPlayed").DefaultValue = easygamesplayedInteger + 187                   Case 288                       statsSqlDataSource.UpdateParameters("MediumGamesPlayed").DefaultValue = mediumgamesplayedInteger + 189                   Case 390                       statsSqlDataSource.UpdateParameters("HardGamesPlayed").DefaultValue = hardgamesplayedInteger + 191               End Select92           End If93   94           statsSqlDataSource.Update()95   96       End Sub97  
CODE - Hangman.aspx 1 <asp:SqlDataSource ID="statsSqlDataSource" runat="server" ConflictDetection="overwritechanges"
2 ConnectionString="<%$ ConnectionStrings:lambanConnectionString %>" DeleteCommand="DELETE FROM [Hangman_Stats] WHERE [PlayerID] = @original_PlayerID AND [GamesPlayed] = @original_GamesPlayed AND [GamesWon] = @original_GamesWon AND [EasyGamesPlayed] = @original_EasyGamesPlayed AND [EasyGamesWon] = @original_EasyGamesWon AND [MediumGamesPlayed] = @original_MediumGamesPlayed AND [MediumGamesWon] = @original_MediumGamesWon AND [HardGamesPlayed] = @original_HardGamesPlayed AND [HardGamesWon] = @original_HardGamesWon"
3 InsertCommand="INSERT INTO [Hangman_Stats] ([PlayerID], [GamesPlayed], [GamesWon], [EasyGamesPlayed], [EasyGamesWon], [MediumGamesPlayed], [MediumGamesWon], [HardGamesPlayed], [HardGamesWon]) VALUES (@PlayerID, @GamesPlayed, @GamesWon, @EasyGamesPlayed, @EasyGamesWon, @MediumGamesPlayed, @MediumGamesWon, @HardGamesPlayed, @HardGamesWon)"
4 OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT PlayerID, GamesPlayed, GamesWon, EasyGamesPlayed, EasyGamesWon, MediumGamesPlayed, MediumGamesWon, HardGamesPlayed, HardGamesWon FROM Hangman_Stats WHERE (PlayerID = @playerid)"
5 UpdateCommand="UPDATE [Hangman_Stats] SET [GamesPlayed] = @GamesPlayed, [GamesWon] = @GamesWon, [EasyGamesPlayed] = @EasyGamesPlayed, [EasyGamesWon] = @EasyGamesWon, [MediumGamesPlayed] = @MediumGamesPlayed, [MediumGamesWon] = @MediumGamesWon, [HardGamesPlayed] = @HardGamesPlayed, [HardGamesWon] = @HardGamesWon WHERE [PlayerID] = @original_PlayerID AND [GamesPlayed] = @original_GamesPlayed AND [GamesWon] = @original_GamesWon AND [EasyGamesPlayed] = @original_EasyGamesPlayed AND [EasyGamesWon] = @original_EasyGamesWon AND [MediumGamesPlayed] = @original_MediumGamesPlayed AND [MediumGamesWon] = @original_MediumGamesWon AND [HardGamesPlayed] = @original_HardGamesPlayed AND [HardGamesWon] = @original_HardGamesWon">
6 <DeleteParameters>
7 <asp:Parameter Name="original_PlayerID" Type="String" />
8 <asp:Parameter Name="original_GamesPlayed" Type="Int32" />
9 <asp:Parameter Name="original_GamesWon" Type="Int32" />
10 <asp:Parameter Name="original_EasyGamesPlayed" Type="Int32" />
11 <asp:Parameter Name="original_EasyGamesWon" Type="Int32" />
12 <asp:Parameter Name="original_MediumGamesPlayed" Type="Int32" />
13 <asp:Parameter Name="original_MediumGamesWon" Type="Int32" />
14 <asp:Parameter Name="original_HardGamesPlayed" Type="Int32" />
15 <asp:Parameter Name="original_HardGamesWon" Type="Int32" />
16 </DeleteParameters>
17 <UpdateParameters>
18 <asp:Parameter Name="GamesPlayed" Type="Int32" />
19 <asp:Parameter Name="GamesWon" Type="Int32" />
20 <asp:Parameter Name="EasyGamesPlayed" Type="Int32" />
21 <asp:Parameter Name="EasyGamesWon" Type="Int32" />
22 <asp:Parameter Name="MediumGamesPlayed" Type="Int32" />
23 <asp:Parameter Name="MediumGamesWon" Type="Int32" />
24 <asp:Parameter Name="HardGamesPlayed" Type="Int32" />
25 <asp:Parameter Name="HardGamesWon" Type="Int32" />
26 <asp:Parameter Name="original_PlayerID" Type="String" />
27 <asp:Parameter Name="original_GamesPlayed" Type="Int32" />
28 <asp:Parameter Name="original_GamesWon" Type="Int32" />
29 <asp:Parameter Name="original_EasyGamesPlayed" Type="Int32" />
30 <asp:Parameter Name="original_EasyGamesWon" Type="Int32" />
31 <asp:Parameter Name="original_MediumGamesPlayed" Type="Int32" />
32 <asp:Parameter Name="original_MediumGamesWon" Type="Int32" />
33 <asp:Parameter Name="original_HardGamesPlayed" Type="Int32" />
34 <asp:Parameter Name="original_HardGamesWon" Type="Int32" />
35 </UpdateParameters>
36 <InsertParameters>
37 <asp:Parameter Name="PlayerID" Type="String" />
38 <asp:Parameter Name="GamesPlayed" Type="Int32" />
39 <asp:Parameter Name="GamesWon" Type="Int32" />
40 <asp:Parameter Name="EasyGamesPlayed" Type="Int32" />
41 <asp:Parameter Name="EasyGamesWon" Type="Int32" />
42 <asp:Parameter Name="MediumGamesPlayed" Type="Int32" />
43 <asp:Parameter Name="MediumGamesWon" Type="Int32" />
44 <asp:Parameter Name="HardGamesPlayed" Type="Int32" />
45 <asp:Parameter Name="HardGamesWon" Type="Int32" />
46 </InsertParameters>
47 <SelectParameters>
48 <asp:ProfileParameter Name="playerid" PropertyName="hangmanplayeridString" />
49 </SelectParameters>
50 </asp:SqlDataSource>
 

View 2 Replies View Related

How Do I Store The Results From A SqlDataSource?

Apr 24, 2007

I have a label on my page that shows a persons name, but in the database it is identified by a ID for indexing purposes.  When I do a UPDATE (users can change other info on the page...not the name though), I want to update by the ID, not the actual name.  Problem is, I don't have the ID (just the name) on the page, so I would have to do a lookup for the ID in the database.  Is there a another  way to do this?  When I select the persons name for display using the SqlDataSource, it's easy to select the ID too.  But how can I use this ID on the UPDATE?  I don't want to reinvent the wheel.

View 1 Replies View Related

Get Number Of Results From SqlDataSource

Aug 27, 2007

Hi all,Is there a way of counting the number of results/rows from an SqlDataSource which uses a select statement like: "SELECT * FROM TABLE1". I need to get this value from the SqlDataSource into the Sub Page_Load. I don't want to bind to any gridviews, repeaters etc. I just want to get the number of rows/results from the SqlDataSource.Is there a way of doing this?Thanks 

View 4 Replies View Related

Can't Get Sqldatasource To Return Results From A Stored Procedure

Aug 1, 2006

I thought I would impliment a new feature of my web page using stored procedures and the SqlDataSource object, for practice or whatever, since I don't normally use that stuff.
This is the stored procedure:set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

-- =============================================
-- Author:Lance Colton
-- Create date: 7/31/06
-- Description:Find the contest winner
-- =============================================

ALTER PROCEDURE [dbo].[AppcheckContest]
-- Add the parameters for the stored procedure here

@BeginDate datetime = '1/1/2006',
@EndDate datetime = '12/31/2006',
@SectionID int = 10,
@WinnerID int = 0 OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.

SET NOCOUNT ON;

-- Insert statements for procedure here

SELECT top 1 @WinnerID = P.UserID
FROM cs_Posts P
WHERE P.PostDate BETWEEN @BeginDate AND @EndDate
AND P.SectionID = @SectionID
AND P.UserID <> 2100 -- I don't want to win my own contest...

AND SettingsID = 1000 -- This number could be different if i had more than one CS installed?

AND IsApproved = 1
ORDER BY NEWID() -- yes this is slow, but it works...

RETURN @WinnerID
END
 It's really simple - just needs to return the one randomly chosen integer userID. I've tested it in query designer or whatever it's called in Management Studio and it works fine there at least.
Thinking I was done the hard part, I created a new web form in visual studio, dropped a SqlDataSource on it, and used the 'configure data source' wizard from the smart tag to do all the work for me. I didn't have any trouble using the wizard to select my stored procedure, and i'm using the sa connection string to simplify my debugging. I tried using the FormParameter / FormField way of getting the output and setting the input parameters. I can't seem to get it working though. There's no errors or anything, just the output isn't coming through.
Here's the code from the aspx codebehind file:Partial Class Contest
Inherits System.Web.UI.Page

Protected Sub btnSelectWinner_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSelectWinner.Click
Dim stuff As New System.Web.UI.DataSourceSelectArguments
SqlDataSource1.Select(stuff)
SqlDataSource1.DataBind()
lblWinnerID.Text = SqlDataSource1.SelectParameters("WinnerID").ToString
End Sub
End Class
 As you can see, I wasn't sure if you're supposed to call databind() or select() to actually get the stored procedure to execute, so I tried both. I was hoping the last line of code there would set the label to the value contained in the @WinnerID parameter, but instead it sets it to "WinnerID".
Here's the code from the .aspx file. Most of this was generated by the Wizard, but I messed around with it a bit. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Contest.aspx.vb" Inherits="Contest" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CPHMain" Runat="Server">
<asp:Button ID="btnSelectWinner" runat="server" Text="Find Winner" />
<asp:Calendar ID="Calendar_From" runat="server"></asp:Calendar>
<asp:Calendar ID="Calendar_To" runat="server"></asp:Calendar>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:appcheck-csConnectionString-sa %>"
SelectCommand="AppcheckContest" SelectCommandType="StoredProcedure" CancelSelectOnNullParameter="False">
<SelectParameters>
<asp:FormParameter FormField="Calendar_From" Name="BeginDate" Type="DateTime" />
<asp:FormParameter FormField="Calendar_To" Name="EndDate" Type="DateTime" />
<asp:Parameter DefaultValue="10" Name="SectionID" Type="Int32" />
<asp:formParameter FormField="lblWinnerID" defaultvalue="666" Direction="InputOutput" Name="WinnerID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
 
<asp:Label ID="lblWinnerID" runat="server" Text="???"></asp:Label>
</asp:Content> 

View 3 Replies View Related

SqlDataSource Returns Fewer Results Than Original Sql Query

Aug 3, 2007

I have a query that I created in SqlServer and then merely copied the code to a sqldatasource. They are both connected to the same db, however the sqldatasource query only returns 6 records and when run in SqlServer, it returns 52 rows which is the correct number.
 Any ideas on what might be causing this? There are no filters on the sqldatasource. It only has that one query. Do they differ in the way they execute sql code?
 Thanks for any help!

View 1 Replies View Related

SqlDataSource And SSMSE Returning Different Results For Same SELECT Command

Oct 2, 2007

Hi,
Hope you guys won't mind this rather newbie question.  I'm writing a simple blog page for my website and have created a SqlDataSource which queries the database for a list of blog post titles (from the web.Blog table) and the number of comments (from the web.BlogComments table).  The SqlDataSource control is:
<asp:SqlDataSource ID="sourceBlogArticles" ProviderName="System.Data.SqlClient" connectionString="<%$ ConnectionStrings:myDatabase %>" runat="server" SelectCommand="SELECT gb.blogID, gb.title, gb.description, gb.tags, gb.dateAdded, COUNT(gbc.blogID) AS noOfComments FROM web.Blog gb LEFT OUTER JOIN web.BlogComments gbc ON gb.blogID = gbc.blogID GROUP BY gb.blogID, gb.title, gb.description, gb.tags, gb.dateAdded ORDER BY gb.dateAdded"></asp:SqlDataSource>
This works perfectly well if each blog entry in the web.Blog table has associated comments in the web.BlogComments table.  However, if there are no comments yet defined in the web.BlogComments table for that blogID then no row is returned in ASP.Net (as checked with a GridView control or similar linked to the data source to view what I get)
 HOWEVER, I think the SELECT command IS correct: if I use the select command as a query in SQL Server Managment Studio Express, I do get the rows returned, with 0 for the number of comments which is what I would expect for that query:
blogID, title, description, tags, dateAdded, noOfComments
1, title 1, description for title 1, tag1, 2007-09-27 06:49:03.810, 32, title 2, description for title 2, tag2, 2007-09-27 06:49:37.513, 03, title 3, description for title3, tag3, 2007-10-02 18:21:30.467, 0
Can anyone help?  The result from the SSMSE query is what I want, yet when I use the very same SELECT statement in my SqlDataSource I don't get any rows returned if the BlogComment count is zero (in the above example I get only the first row).  Many thanks for any suggestions!

View 6 Replies View Related

Get Value From Datasource In Codebehind

Apr 23, 2007

Lets say I have a Sqldatasource that uses the following SelectCommand="SELECT category,name FROM table". How do I get the value on category from my datasource in code behind if I know that my selectcommand always will return one row? Can I write something like datasource.items["category"].Value? Thanks for your help! 

View 1 Replies View Related

Setting Up/accesing Database In VB Codebehind

Jul 9, 2006

Hey All,
I'm very new to ASP.NET and have recently begun using the databinding functionality.  So far, all I've had to do is drag and drop the various controls and then use the data source wizard to set up an appropriate query.  However, now I've got a bit of a different need.  In the VB codebehind, i need to be able to ask whether something is true in the database, and then if it is, carry out functions.  So, for example, what I need to do is:
if (SQLStatement "Select charttype FROM charts WHERE datasource = " & dropdownlist1.selecteditem.tostring()) Then
'do whatever
end if
Trouble is, I don't know how I would go about binding the data so that I could access it in this way.  Any guidance would be very much appreciated. 
Thanks,J Rankin  

View 1 Replies View Related

String Variable From CodeBehind To Html

Dec 3, 2007

Hi Folks,
How can i pass a string variable from code behind page to html page on event fire. i want to pass sql qerry to SelectCommand (SELECT * FROM [Tickets] WHERE ([TicketNo] = @TicketNo)) in some variable from codebehind on some event fire.
<asp:SqlDataSource ID="sqldsTickets" runat="server" ConnectionString="<%$ ConnectionStrings:IMTicketingConnectionString %>" SelectCommand="" >
<SelectParameters>
<asp:SessionParameter Name="TicketNo" SessionField="test" Type="Int64" />
</SelectParameters>
</asp:SqlDataSource>
 Thanks in advance

View 4 Replies View Related

Read Rows AND An Output Parameter From Codebehind Returned By Stored Proc?

Feb 5, 2008

I have a stored procedure that returns a resultset AND an output parameter, pseudocode:myspGetPoll@pollID int,@totalvoters int outputselect questionID,question from [myPoll] where pollID=@pollID  @totalvoters=(select count(usercode) from [myPoll] where pollID=@pollID)1. In my code behind I'd like to read both the rows (questionID and question) as well as total results (totalvoters) How could I do so?2. what would be the signature of my function so that I can retreive BOTH a resultset AND a single value?e.g.: private function getPollResults(byval pollID as integer, byref totalvoters as integer) as datasetwhile reader.read    dataset.addrow <read from result>end whiletotalvoters=<read from result>end functionThanks!

View 2 Replies View Related

SELECT A Single Row With One SqlDataSource, Then INSERT One Of The Fields Into Another SqlDataSource

Jul 23, 2007

What is the C# code I use to do this?
I'm guessing it should be fairly simple, as there is only one row selected. I just need to pull out a specific field from that row and then insert that value into a different SqlDataSource.

View 7 Replies View Related

Is There A Way To Hold The Results Of A Select Query Then Operate On The Results And Changes Will Be Reflected On The Actual Data?

Apr 1, 2007

hi,  like, if i need to do delete some items with the id = 10000 then also need to update on the remaining items on the with the same idthen i will need to go through all the records to fetch the items with the same id right?  so, is there something that i can use to hold those records so that i can do the delete and update just on those records  and don't need to query twice? or is there a way to do that in one go ?thanks in advance! 

View 1 Replies View Related

SQL Server 2008 :: Elegant Way For Returning All Results When Subquery Returns No Results?

Mar 25, 2015

I have four tables: Customer (CustomerId INT, CountyId INT), County (CountyId INT), Search(SearchId INT), and SearchCriteria (SearchCriteriaId INT, SearchId INT, CountyId INT, [others not related to this]).

I want to search Customer based off of the Search record, which could have multiple SearchCriteria records. However, if there aren't any SearchCriteria records with CountyId populated for a given Search, I want it to assume to get all Customer records, regardless of CountyId.

Right now, I'm doing it this way.

DECLARE @SearchId INT = 100
SELECT * FROM Customer WHERE
CountyId IN
(
SELECT CASE WHEN EXISTS(SELECT CountyId FROM SearchCriteria WHERE SearchId = @SearchId)
THEN SearchCriteria.CountyId

[Code] .....

This works; it just seems cludgy. Is there a more elegant way to do this?

View 4 Replies View Related

Need To Display Results Of A Query, Then Use A Drop Down List To Filter The Results.

Feb 12, 2008

Hello. I currently have a website that has a table on one webpage. When a record is clicked, the primary key of that record is transfered in the query string to another page and fed into an sql statement. In this case its selecting a project on the first page, and displaying all the scripts for that project on another page. I also have an additional dropdownlist on the second page that i use to filter the scripts by an attribute called 'testdomain'. At present this works to an extent. When i click a project, i am navigated to the scripts page which is empty except for the dropdownlist. i then select a 'testdomain' from the dropdownlist and the page populates with scripts (formview) for the particular test domain. what i would like is for all the scripts to be displayed using the formview in the first instance when the user arrives at the second page. from there, they can then filter the scripts using the dropdownlist.
My current SQL statement is as follows.
SelectCommand="SELECT * FROM [TestScript] WHERE (([ProjectID] = @ProjectID) AND ([TestDomain] = @TestDomain))"
So what is happening is when testdomain = a null value, it does not select any scripts. Is there a way i can achieve the behaivour of the page as i outlined above? Any help would be appreciated.
Thanks,
James.

View 1 Replies View Related

Stored Proc Results Are Displaying In The Messages Tab Instead Of Results Tab- URGENT

May 14, 2008




Hi All,
I have a stored proc which is executing successfully...but the results of that stored proc are displaying in the Messages Tab instaed of results Tab. And in the Results Tab the results shows as 0..So, Any clue friends..it is very urgent..I am trying to call this stored proc in my Report in SSRS as well but the stored proc is not displaying there also...Please help me ASAP..

Thanks
dotnetdev1

View 4 Replies View Related

Individual SqlDataSource() Or Common SqlDataSource() ?

Mar 8, 2007

i am using visual web developer 2005 with SQL Express 2005 with VB as the code behindi have one database and three tables in itfor manipulating each table i am using separate SqlDataSource() is it sufficient to use one SqlDataSource() for manipulating all the three tables ? i am manipulating all the tables in the same page only please help me

View 1 Replies View Related

Mind-boggling Gridview Results! Different Results For Different Teams..

Jun 18, 2008

Hi all, I have the following SQLDataSource statement which connects to my Gridview:<asp:SqlDataSource ID="SqlDataSourceStandings" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"  SelectCommand="SELECT P.firstName, P.lastName, T.teamName, IsNull(P.gamesPlayed, 0) as gamesPlayed, IsNull(P.plateAppearances,0) as plateAppearances, IsNull( (P.plateAppearances - (P.sacrifices + P.walks)) ,0) as atbats, IsNull(P.hits,0) as hits, P.hits/(CONVERT(Decimal(5,2), IsNull(NullIF(P.atbats, 0), 1))) AS [average], (P.hits + P.walks)/(CONVERT(Decimal(5,2), IsNull(NullIF( (P.atbats + P.sacrifices + P.walks) , 0), 1)))  AS [OBP], (P.hits - (P.doubles + P.triples + P.homeRuns) + (2 * P.doubles) + (3 * P.triples) + (4 * P.homeRuns)) / (CONVERT(Decimal(5,2), IsNull(NullIF(P.atbats, 0), 1))) AS [SLG], P.singles, P.doubles, P.triples, P.homeRuns, P.walks, P.sacrifices, P.runs, P.rbis FROM Players P INNER JOIN Teams T ON P.team = T.teamID ORDER BY P.firstName, P.lastName"></asp:SqlDataSource>There are 8 teams in the database, and somehow the average and obp results are as expected for all teams except where T.teamID = 1.  This doesn't make sense to me at all!  For example, I get the following results with this same query: First NameLast NameTeamGPPAABHAVGOBPSLG1B2B3BHRBBSACRRBI

BrianAustinHope83432230.7187500.7352941.15625014612201221

GabrielHelbigSafe Haven62119141.0000000.9375002.1428576404111519

MarkusJavorSafe Haven82927200.8695650.8000001.21739114501021218

RobBennettMelville83029240.8275860.8333331.55172411904102117

AdamBiesenthalSafe Haven82929210.9130430.9130431.56521712631001015

ErikGalvezMelville82625180.7200000.7307691.24000011322101015 As you can see, all teams except for Safe Haven's have the correct AVG and OBP.  Since AVG is simply H/AB, it doesn't make sense for Gabriel Helbig's results to be 1.00000. Can anyone shed ANY light on this please?Thank you in advance,Markuu  ***As a side note, could anyone also let me know how I could format the output so that AVG and OBP are only 3 decimal places? (ex: 0.719 for the 1st result)*** 

View 2 Replies View Related

Removing Individual Results From A Paged Set Of Results.

Oct 19, 2007

Hi,
I have a web form that lets users search for people in my database they wish to contact. The database returns a paged set of results using a CTE, Top X, and Row_number().
I would like to give my users to option of removing individual people from this list but cannot find a way to do this.
I have tried creating a session variable with a comma delimited list of ID's that I pass to my sproc and use in a NOT IN() statement. But I keep getting a "Input string was not in a correct format." Error Message.
Is there any way to do this? I am still new to stored procedures so any advice would be helpful.
Thanks
 

View 3 Replies View Related

PASTE SQL RESULTS INTO EXCEL - Funny Results

Jan 30, 2008

Hi, when I copy and paste results from query analyzer into Excel it appears that values with zeroes at the end loose the zeroes. Example, if I copy and paste V128.0 into an Excel cell it comes out as V128 or if I copy 178.70 it displays as 178.7 - any ideas? I'm using SQL Enterprise Manager for 2000.

View 6 Replies View Related

Asp:sqldatasource - Sum And Contains

Aug 20, 2006

I have an asp:sqldatasource which is bound to a gridviewIn addition to this I would like it to a) see if there is a specif row/ item in it (ie item_id = 10 for any of the rows it has received) as I conditionally want to show another item outside of the gridview subject to if it is in the gridview or notb) show the sum of all the values within a certain column of returned rowsMany thanks

View 1 Replies View Related

SqlDataSource

Oct 11, 2006

How do I get the result of this select into a variableDim sqldsFindUserId As SqlDataSource = New SqlDataSource        sqldsFindUserId.ConnectionString = ConfigurationManager.ConnectionStrings("bluConnectionString2").ToString        sqldsFindUserId.SelectCommandType = SqlDataSourceCommandType.Text        Dim myUserIdCmd As String = "select pkUser from tblUsers where strDisplayName='" + myDisplayname + ""        sqldsFindUserId.SelectCommand = myUserIdCmd  '  The result  of this select statement is to be stored in a variable, how do I do it?

View 2 Replies View Related

SqlDatasource

Dec 18, 2006

Hi all

View 2 Replies View Related

Sqldatasource

Jan 15, 2007

hi all,
in all my 2.0 learnings and books i keep coming across the page element <asp:sqldatasource>.
I have always (in 1.1) used server side connections and adapters to bind my Sql datasets to any control needed.  Now that im learning 2.0 im finding it difficult to understand using control on the page to bind my data.  Can someone explain the benefits of using this data source?  Ideally i would like to keep my data access layer separate from my presentation layer but i'd really like to understand why this method seems so popular.
thanks in advance,
mcm

View 2 Replies View Related

Using SQLDataSource

Feb 23, 2007

Hi, I am new to ASP.NET 2.0 and I am trying to use VWB to bind my web site to a SQL Express edition. I used SQLDataSource to specify the .mdf file so I can connect to my tables but when I click on the advanced button to generate the Insert, Update, Delete SQL I find it grayed out and it cannot be clicked. I looked into several tutorials online and I couldn't find the problem, can anyone explain what I am missing or doing wrong? Any suggestion is very appreciated. Thanks 

View 2 Replies View Related

SQLDataSource

Mar 30, 2007

SELECT * FROM [CONTACTS] WHERE @ddl_value LIKE '%@txt_value%'
 
Why doesn't this not working
I am using SQLdatasource control to bind a gridview
If my query is wrong then what might be the correct one to work with like operator in the sqldatasource
Can any ony help me!

View 4 Replies View Related







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