DataSource Controls :: Add Sqldatasource In Codebehind?
Jul 31, 2010
i use below sqldatasource for search within a gridview and it is working fine.i just add this control and set gridview datasource id to sql datasource id .but i need the same in codebehind dynamically.i need like this becuase i need to search in three textbox but before i use one textbox. so could someone show me a example how i add a sqldatasourse in code behind and set filter parameter for search from a gridview.
I have a page called Page2.aspx and it is called by another page called Page1.aspx and Page1.aspx passes two parameters namely: Name and Category to Page2.aspx. Does anyone know why the following code from Page2.aspx is not working and it keeps giving an error message as follows: " You have declare the parameter @Username".
I would like to move all of this to codebehind so it's easier to work with programmatically. For instance the PracticeId is a selection from a dropdownlist that is populated from another table... i need to determine what the current selection is first so i can display the record / bind properly.
i have two sqldatasource controls. one i use to display data in textbox's ,filter'd by a select parameter in page behind code. Once checked, i want to copy this data to the other datasource ,by selecting checkbox.Then display this data in detailsview control.
At present the two datasource controls declared , render data to the page simultaneously during pageload. I want to first check data in textbox's from first source, before second datasource is rendered to screen. note, both are filtered by a page variable. i wish to leave the textbox datasource control in situ, as other controls and code depend on it.The other detailsview datasource is my problem?
I'm trying to use a stored procedure in my codebehind insted of a sqldatasource to insert some data, and return the identity fields. But I keep getting tripped up on the output paramaters. What am I missing?
My code behind:
[Code]....
And, here's my stored procedure
Create PROCEDURE [dbo].[123] ( @MatterToCloneID varchar(15), @ClonedMatterID int OUTPUT, @ClientIDOUT int OUTPUT, @ExistingClientIDOUT int OUTPUT ) AS BEGIN DECLARE @ExistingClientID int, @PendingClientID int, @BillingAddress varchar(200), @BillingCity varchar(200), @BillingState varchar(100), @BillingZipCode varchar(20), @BillingCountry varchar(200) SELECT @ExistingClientID = ExistingClientID, @PendingClientID = PendingClientID, @BillingAddress = BillingAddress, @BillingCity = BillingCity, @BillingState = BillingState, @BillingZipCode = BillingZipCode, @BillingCountry = BillingCountry FROM tNewMatters WHERE MatterID = @MatterToCloneID Set @ClientID = @EClientID Set @PendingClientID = @PendingClientID Set @BillingAddress = @BillingAddress Set @BillingCity = @BillingCity Set @BillingState = @BillingState Set @BillingZipCode = @BillingZipCode Set @BillingCountry = @BillingCountry INSERT into tNewMatters (MatterName, ClientID, PendingClientID, BillingAddress, BillingCity, BillingState, BillingZipCode, BillingCountry) Values ('Enter Client Name', @ExistingClientID, @PendingClientID, @BillingAddress, @BillingCity, @BillingState, @BillingZipCode, @BillingCountry) Select @ClonedMatterID = scope_identity() Select @ClientIDOUT = @ClientID Select @ExistingClientIDOUT = @ExistingClientID END
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.
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.
Which one is better for me to store urls of my products images while i was trying to bind images with gridview. provide me some code snippet to bind images to gridview with XMLDataSource.
If I have a SqlDataSource like this one, is it possible to add a DataRelation in the sqldatasource? Or do I need to create a DataSet and add the Relation in CodeBehind?
I have an SqlDataSource query that should use an input parameter for multiple integer values, like:
select * from table1 where TableID IN (1,2,3,4,5)
->
select * from table1 where TableID IN (@IDValues)
How do I do that ? Default parameter settings won't work, returning "invalid integer value" . I suppose that parameter should be passed as some kind of array that SQL recognizes as multiple integer values , but what's the correct way of setting this ?
i want to ask how to i set variable in asp:sqldatasource in sqlcommand in asp.net c#.... This is my code
asp.net <dx:ASPxListBox ID="lsAssignToko" runat="server" DataSourceID="SqlDataSource6" TextField="NAMA" ValueField="ID" AutoPostBack="true" EnableCallbackMode="True" SelectionMode="CheckColumn" OnSelectedIndexChanged="lsAssignToko_SelectedIndexChanged"> <Columns> <dx:ListBoxColumn FieldName="ID"/> <dx:ListBoxColumn FieldName="NAMA" /> </Columns> </dx:ASPxListBox> <asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:Ora2010 %>" ProviderName="<%$ ConnectionStrings:Ora2010.ProviderName %>" SelectCommand="SELECT ID, NAMA FROM REF_TOKO WHERE ID IN ( :inTOKO ) ORDER BY NAMA"> <SelectParameters> <asp:SessionParameter Name="inTOKO" SessionField="inTOKO" Size="200" Type="String" /> </SelectParameters> </asp:SqlDataSource> c# string dummy = ""; string data = ""; string inTK = ""; string inTOKO = ""; //string inTOKO1 = ""; int pot; for (int i = lsToko.SelectedItems.Count - 1; i >= 0; i--) { string tok = lsToko.SelectedItem.Text.ToString(); data = lsToko.SelectedItem.Value.ToString(); dummy = dummy + "" + data + ","; int index = lsToko.SelectedItem.Index; lsToko.Items.RemoveAt(index); } if (lsToko.SelectedItems.Count <= 1) { inTK = dummy.Length.ToString(); pot = int.Parse(dummy.Length.ToString()) - 1; inTOKO = dummy.Substring(0, pot); } Session["inTOKO"] = inTOKO;
the problem is where in my variable inTOKO consist of couple of value... Example while variable inTOKO = one value success but while value inTOKO = two value error inTOKO = 1101111 => success inTOKO = 1101111,1211321 => not success
I have an editable grid where user can add/edit data. They also have the option to load previously entered data from last month. When the user then clicks save, i want to readd this newly modified data as a new record for this month. So basically I want to call the insertcommand, but it does not work. My 'save' method just 'updates' the records.
Providing sqldatasource, grid and save method <asp:SqlDataSource ID="SqlDataSourceLoadActivities" runat="server" [code].....
I use MySQL database and SqlDataSource controls. I generate update and insert queries in my code behind.how I can get a list of columns from the SqlDataSource control?
I need to run a query on server1.database1 where subquery meets criteria on server2.database2. Here's my code:
[Code]....
I tried replacing connectionstrings:connectionstring2 with server2.database2.dbo.scheduledvisits but it didn't know where to look to find that besides by using connectionstring1.