DataSource Controls :: Return Value From Sql In GridView?
Aug 28, 2010
I have textbox for searching a Names in My database. I return the information from the Select Statement in GridView, but i want to know the number of affected rows. How to do that?
I am trying to return a dataset. I must be doing something wrong. The returned dataset in this sample code indicates there is a datatable, Users, but there are no datarows. What am I doing wrong? This example is only using the rows.count, but of course I really need to use the whole datatable as the datasource for a gridview.
[Code]....
Public Function getmyds() As DataSet Dim dsUser1 As DataSet = New DataSet() Dim tbUser1 As DataTable = dsUser1.Tables.Add("Users") tbUser1.Columns.Add("UserName") tbUser1.Columns.Add("Days Remaining") tbUser1.Columns.Add("UserAccountControl") Dim rwDefaultUser1 As DataRow = tbUser1.NewRow() rwDefaultUser1("UserName") = "John Smith" rwDefaultUser1("Days remaining") = 100 rwDefaultUser1("userAccountControl") = "Enabled" Return dsUser1 End Function
I have created a stored procedure that reset my tables' identity value. The store procedure works fine when I didrectly run it in my ms sql server 2008. It reset my table Identity value However, when I call it from my function reset, it returns -1, and does not reset my table identitity value. The function to restet my identity value is:
[Code]....
My stored procedure is
[Code]....
To call the the function:
Dim result As Integer = util.resetTableIdentity("myTable", "id", 60) util.print(result)
I got result is -1, and it does ot reset my table identity. Why? How to resove it?
I have 2 tables. Table_A has one to many relationship with Table_B.
For example. Table_A has an ApplicantKey and in Table_B I am storing (Resume_name and CoverLetter_name for the Applicant). Joined by ApplicantKey
Now when I join them and execute the query obviously it returns me two rows. But what I want is that it should return only one row with Columns like Resume_name, CoverLetter_Name
accessing the return value of the SQLDataReader. My code is below. Actually the variable that I assigned my SQLDatareader object to is say HasRows property=true. But I am having trouble accessing the return value. And I get the error when I use the following code .Text =SQLDataReader("Contact Name").ToString I get the following error message: Invalid attempt to read when no data is present.
con = New SqlConnection(ConfigurationManager.ConnectionStrings("Connect").ConnectionString) Dim getDirectorsCMD As SqlCommand = New SqlCommand("dbo.spGetDirector", con) getDirectorsCMD.CommandType = CommandType.StoredProcedure Dim myParm As SqlParameter = getDirectorsCMD.Parameters.Add("@BuildingTID", SqlDbType.Int, 15) myParm.Value = ddlBuilding.SelectedValue [code]...
I followed this BRILLIANT article and found out how to make a data layer, i just need the insert method in this code to return the ID of the record inserted.
For example, when the user captures the details, the save button is clicked, i will want to display in a label "Your Reference Number is "
try and have look at the article so you will understand how the code is, so it will not be hard to edit my code.
I want to select dates that also fallin the range. Heres the scenario: I have an event from 01/20/2010 TO 01/25/2010. So right now it would only return a date of 01/20/2010. How could I return 01/20/2010, 01/21/2010 , 01/22/2010, 01/23/2010, 01/24/2010, 01/25/2010? Mind you only a start and end date are in the database.
I have an autoincrement ID on some table.I need to know what is the ID of the new row when I add the object using InsertOnSubmit, but this method returns void.What is the common way of doing this.
I have a select statement in a stored procedure and want to be able to retrieve the key column value (PRODUCTID)and return it as Output when Select statement is executed on input Parameter (NAME).
addition, return two further output values (COST,TOTAL).
note the grid control expects to receive all values at once! so i need to get out these values at the same instance of execution.
Select productID,COST,QUANTITY,NAME,TOTAL,DATE FROM PRODUCTS WHERE NAME=@NAME
You notice "Cough" is in the adidescription column twice. I would like to return only one row for adidescription with the same value. So what I want returned is this:
Cannot implicitly convert type 'System.Data.SqlClient.SqlParameter' to 'string' I have a stored procedure on SQL 2000 returning an email from a database table (aspnet_Membership). The email type from the table is nvarchar. I have a method (in C# in the code behind) that gets that value. But the debugger doesn't like the last line:
return returnEmail; // returnEmail is a string variable we created to capture the stored procedure's return value
I've tried doing returnEmail.toString() in several places, but still get the same error message for the last line of code (returning the email).
I have a stored procedure which returns a value to state if the userlogin is valid. but i want to return the data and store it in a data session as i will require the user details in the checkout page.
is it best to get individual parameters out of the stored procedure then assign the variables to a datatable which is then assigned to session Or how can i get all the details returned from the stored procedure for the table? not sure which would be the most effective solution?
On one line the Code may be OX01 and shape Hexagon for example
Then the next line the code is still OX01 but the shape is Triangle.
What I want to do is be able to pull back data for every line that is equal to a unique Code column. in the above example OX01 Hexagon would be returned but not OX01 Triangle.
I've tried using SELECT DISTINCT but it brings back all records and doesn't filter them correctly.
I've considered having another column which could have Child/Parent data so that only the parent is returned but i'm sure there must be a better way of doing this.
I am using the query listed below which includes multiple joins, in the result of the query I need to do some value replacement valuesExample: db.ASSETS.BUILDING_ID=300 that ID does not exist in db.BUILDINGS, in that case I need to return BUILDING_ID=0, db.BUILDINGS.NAME="Unassigned"
I've looked all over for this answer and had to resort to several resources. I wanted to post this here because it was so hard for me to find a simple example. If it exist other places then please excuse my post and put references to it on a reply.
So, How do I return the Primary Key Identity when I click the control with the 'Insert' command on a FormView? (With very least minimal code) Help me if there's a quicker way.
Protected Sub sqlSource_Inserted() Dim cmd as System.Data.Common.DbCommand = e.command Dim strID as String sqlSource.InsertParameters("ID").DefaultValue = cmd.Parameters("@ID").Value.ToString() strID = sqlSource.InsertParameters("ID").DefaultValue.ToString() lblResults.Text = strID End Sub
I am trying to fill a gridview with the data from Product table selecting few columns . I am using 3 - tier architecture and in DAL getproduct(userid) I am writing the query but cannot figure out exactly how to get that working .. here is piece of method I wrote
I am working on a small project. I ran the query below to get the maximum userid and increase it by 1 to create a new userid. However, when I run the query, it does not display the values that I enter into the database using insert statement. For example, if I open the table called login, I can see there are three records. If Irun the select statement, it only return one record which is the one that I enter manually when I first created the table. If I run the same select statement and give it a user id that I created, it returns the correct result.