473,785 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get just one record in gridview

6 New Member
I have a stored procedure in mysql and I am calling it via a method and objectdatasourc e. I have two select methods. One that gets a list of employees and the other that gets one specific employee by passing the employee id via a parameter.

I have two gridviews, one for displaying all employees and one for displaying one employee record. The user should be able to enter the employee id in the textbox and the gridview should display the employee's record. My code is working for displaying all employees but not for displaying one specific employee. The code compiles but does not display any info. Here is my code:
Expand|Select|Wrap|Line Numbers
  1. <asp:objectdatasource id="ObData2" runat="server" dataobjecttypename="EmpData" typename="Employee" selectmethod="getEmployee" ><selectparameters>asp:controlparameter controlid="employeeid" name="eId" propertyname="text" type="string" /></selectparameters>
  2.  
  3.  
  4. <asp:gridview id="GridView2" action="databind" runat="server" datasourceid="ObData2"datakeynames="EmployeeID" allowpaging="True" autogenerateeditbutton="True" autogeneratecolumns="True"emptydatatext="No Records" allowsorting="True" > 
  5.  
Expand|Select|Wrap|Line Numbers
  1. [DataObjectMethod(DataObjectMethodType.Select)] 
  2. public void getEmployee(string eId) 
  3. MySqlCommand cmd = new MySqlCommand(); 
  4. try 
  5. DB_Connection conn = new DB_Connection(); 
  6. cmd.Connection = (MySqlConnection)conn.DBConnect(); cmd.CommandText = "getEmployee"; 
  7. cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("EMPLOYEEID", eId); 
  8. cmd.ExecuteNonQuery(); 
  9. }
Sep 26 '07 #1
10 3680
davef
98 New Member
I have a stored procedure in mysql and I am calling it via a method and objectdatasourc e. I have two select methods. One that gets a list of employees and the other that gets one specific employee by passing the employee id via a parameter.

I have two gridviews, one for displaying all employees and one for displaying one employee record. The user should be able to enter the employee id in the textbox and the gridview should display the employee's record. My code is working for displaying all employees but not for displaying one specific employee. The code compiles but does not display any info. Here is my code:


<asp:objectdata source id="ObData2" runat="server" dataobjecttypen ame="EmpData" typename="Emplo yee" selectmethod="g etEmployee" ><selectparamet ers>asp:control parameter controlid="empl oyeeid" name="eId" propertyname="t ext" type="string" /></selectparameter s>



<asp:gridview id="GridView2" action="databin d" runat="server" datasourceid="O bData2"datakeyn ames="EmployeeI D" allowpaging="Tr ue" autogenerateedi tbutton="True" autogeneratecol umns="True"empt ydatatext="No Records" allowsorting="T rue" >


[DataObjectMetho d(DataObjectMet hodType.Select)]
public void getEmployee(str ing eId)
{
MySqlCommand cmd = new MySqlCommand();
try
{
DB_Connection conn = new DB_Connection() ;
cmd.Connection = (MySqlConnectio n)conn.DBConnec t(); cmd.CommandText = "getEmploye e";
cmd.CommandType = CommandType.Sto redProcedure; cmd.Parameters. Add("EMPLOYEEID ", eId);
cmd.ExecuteNonQ uery();
}
If I understand your code correctly, you call the same getEmployee method for displaying all or one Employee. The difference should be the string eld value. Check what's being sent into this method for a single Employee and see what your getEmployee sp should yield in return.
Sep 26 '07 #2
newbieAl
6 New Member
If I understand your code correctly, you call the same getEmployee method for displaying all or one Employee. The difference should be the string eld value. Check what's being sent into this method for a single Employee and see what your getEmployee sp should yield in return.
No I have two methods. One for calling all employees and then one for calling one specific employee. This is the one i'm having a problem with as it is returning no records. The sp should return all fields in the record as this is a select * from employees where employeeid= empid;
Sep 26 '07 #3
davef
98 New Member
No I have two methods. One for calling all employees and then one for calling one specific employee. This is the one i'm having a problem with as it is returning no records. The sp should return all fields in the record as this is a select * from employees where employeeid= empid;
Do you have a separate sp for each .NET method, too?
Sep 26 '07 #4
newbieAl
6 New Member
Do you have a separate sp for each .NET method, too?

Yes, I do have separate methods for each.
Sep 26 '07 #5
davef
98 New Member
Yes, I do have separate methods for each.
Did you try to step into the C# code of your single employee select method in debug?
Sep 26 '07 #6
newbieAl
6 New Member
Did you try to step into the C# code of your single employee select method in debug?

Yes, but it just runs through the code and nothing happens.
Sep 26 '07 #7
davef
98 New Member
Yes, but it just runs through the code and nothing happens.
The select method that you use in the object datasource is void. Make it return a dataset or datatable, then bind to it again.
Sep 26 '07 #8
prabunewindia
199 New Member
hi friend,
what davef told is correct.

and one more thing, u used the below one

cmd.ExecuteNonQ uery();

this will return the no of rows affected due to ur query, not the details in row.
normally it will be one, if u r getting one employee record

please use the following
SqlDataReader dr = cmd.ExecuteRead er();
return dr;

and make the method as Public SqlDataReader ....

Prabu

The select method that you use in the object datasource is void. Make it return a dataset or datatable, then bind to it again.
Sep 26 '07 #9
newbieAl
6 New Member
hi friend,
what davef told is correct.

and one more thing, u used the below one

cmd.ExecuteNonQ uery();

this will return the no of rows affected due to ur query, not the details in row.
normally it will be one, if u r getting one employee record

please use the following
SqlDataReader dr = cmd.ExecuteRead er();
return dr;

and make the method as Public SqlDataReader ....

Prabu
Great, thanks. Is there a good code example that I could follow for dataset and reader?
Sep 26 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1223
by: fig000 | last post by:
Hi, I'm trying to use the sqldatasource control and a detailsview to create a fully functional data entry screen; it's quite easy. I can see the strength of creating a master grid associated with a detailsview that gives you access to the record you choose in the grid. However one of the basic functions of this type of screen is the ability to enter a search term and have the grid display the record that is closest the search term....
10
5309
by: NH | last post by:
I have a girdview with paging enabled. How can I add a message in the footer to say "Viewing records 1-15 of 45" etc Thanks
0
1874
by: jeffmagill | last post by:
Hi Everybody, I'm really hoping that someone can help me out because I have spent too much time on this project already! Basically, I have a DetailsView that handles all the Edits for a GridView - each row has an edit button and clicking on this should trigger that record to be loaded into the DetailsView for editing. The problem is that the record never gets loaded into the DetailsView. Instead, the DetailsView always and only...
1
3699
by: JayD | last post by:
Here is the problem: Using asp.net 2.0 to create a web app with standard master table gridview and child detailsview with insert capability. SQL Server 2000 database on the backend. Using Visual Web Developer for front-end development. I want to insert new records in detailsview based on selected gridview record. All the fields in "INSERT" mode are blank, which is okay EXCEPT that I want the child ID to be that of the selected...
0
1168
by: bhawin13 | last post by:
Hello, I am not able to see any records in GridView2. GridView2 is not shown. I tried to print record count of datatable and it shows there is records but nothing is shown in gridview2. First I try to list products table in gridview1 I have added one column which shows select with hyperlink When I click on select It adds that row from Products table to datatable dt for gridview1 GridView1_SelectedIndexChanged event is written.
1
1822
by: Dica | last post by:
i need to allow the user to select a row from my dataGrid for editing. as such, i include the record ID in the first column and then extract like so when retrieving the record details: protected void gvLocations_edit(object sender, GridViewEditEventArgs e) { // load the record details into the edit fields // GridView gvRecord = (GridView)sender; string sThisRecord = gvRecord.Rows.Cells.Text; ...
0
966
by: Mike N. | last post by:
Greetings: I have a gridview control which contains several hundred thousand records. The user is able to sort by a multitude of fields. I want to be able to put in a search string for one of those fields and have the gridview go to that page and select that record. I don't want to filter the data, it's important that the gridview keep all of the records because I have the rownumber displayed as a ranking. In other words, each time...
2
1335
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, is it possible, when a user select a record in a GridView (ASP.NET 2.0 - VS 2005) show only this record in this GridView and hidden all others records? Thanks a lot. -- Luigi
7
11061
by: =?Utf-8?B?SnVsaWEgQg==?= | last post by:
Hi all, this is a second post, so apologies, but I never had an answer to my first post (several weeks ago) and I really need some help. I'm using a .Net 2.0 Gridview which is populated using an ObjectDataSource which calls on a method in a class. This all works fine. The Gridview has a select button automatically generated. When the user presses this I want to be able to take the data from the selected record and use it. However...
0
9485
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9958
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3662
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.