如何在gridview中只获取一条记录 [英] how to get just one record in gridview

查看:114
本文介绍了如何在gridview中只获取一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mysql中有一个存储过程,我通过方法和objectdatasource调用它。我有两个选择方法。一个获取员工列表,另一个获取一个特定员工,方法是通过参数传递员工ID。


我有两个gridviews,一个用于显示所有员工,一个用于显示一个员工记录。用户应该能够在文本框中输入员工ID,gridview应该显示员工的记录。我的代码用于显示所有员工,但不显示特定员工。代码编译但不显示任何信息。这是我的代码:

I have a stored procedure in mysql and I am calling it via a method and objectdatasource. 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:

展开 | 选择 | Wrap | 行号

推荐答案


我在mysql中有一个存储过程,我通过方法和objectdatasource调用它。我有两个选择方法。一个获取员工列表,另一个获取一个特定员工,方法是通过参数传递员工ID。


我有两个gridviews,一个用于显示所有员工,一个用于显示一个员工记录。用户应该能够在文本框中输入员工ID,gridview应该显示员工的记录。我的代码用于显示所有员工,但不显示特定员工。代码编译但不显示任何信息。这是我的代码:


< asp:objectdatasource id =" ObData2" RUNAT = QUOT;服务器" dataobjecttypename = QUOT; EMPDATA"类型名称= QUOT;员工" selectmethod = QUOT; getEmployee的" >< selectparameters> asp:controlparameter controlid =" employeeid"名称= QUOT; EID" PROPERTYNAME = QUOT;文本"类型= QUOT;串QUOT; />< / selectparameters>



< asp:gridview id =" GridView2"行动= QUOT;数据绑定" RUNAT = QUOT;服务器"的DataSourceID = QUOT; ObData2"的DataKeyNames = QUOT;雇员" allowpaging = QUOT;真" AutoGenerateEditButton属性= QUOT;真" autogeneratecolumns =" True" emptydatatext =" No Records" allowsorting = QUOT;真" >


[DataObjectMethod(DataObjectMethodType.Select)]

public void getEmployee(string eId)

{

MySqlCommand cmd = new MySqlCommand();

尝试

{

DB_Connection conn = new DB_Connection();

cmd.Connection =(MySqlConnection)conn.DBConnect(); cmd.CommandText =" getEmployee" ;;

cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(" EMPLOYEEID",eId);

cmd.ExecuteNonQuery();

}
I have a stored procedure in mysql and I am calling it via a method and objectdatasource. 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:objectdatasource id="ObData2" runat="server" dataobjecttypename="EmpData" typename="Employee" selectmethod="getEmployee" ><selectparameters>asp:controlparameter controlid="employeeid" name="eId" propertyname="text" type="string" /></selectparameters>



<asp:gridview id="GridView2" action="databind" runat="server" datasourceid="ObData2"datakeynames="EmployeeID" allowpaging="True" autogenerateeditbutton="True" autogeneratecolumns="True"emptydatatext="No Records" allowsorting="True" >


[DataObjectMethod(DataObjectMethodType.Select)]
public void getEmployee(string eId)
{
MySqlCommand cmd = new MySqlCommand();
try
{
DB_Connection conn = new DB_Connection();
cmd.Connection = (MySqlConnection)conn.DBConnect(); cmd.CommandText = "getEmployee";
cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("EMPLOYEEID", eId);
cmd.ExecuteNonQuery();
}



如果我正确理解你的代码,你可以调用相同的getEmployee方法来显示所有或一个Employee。差异应该是字符串字段值。检查单个Employee发送到此方法的内容,并查看getEmployee sp应该返回的内容。

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.



如果我正确理解您的代码,您调用相同的getEmployee方法来显示所有或一个Employee。差异应该是字符串字段值。检查单个Employee发送到此方法的内容,并查看getEmployee sp应该返回的内容。
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.



不,我有两种方法。一个用于呼叫所有员工,然后一个用于呼叫一个特定员工。这是我遇到问题的一个,因为它没有返回任何记录。 sp应返回记录中的所有字段,因为这是来自雇员的select *,其中employeeid = empid;

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;



否我有两种方法。一个用于呼叫所有员工,然后一个用于呼叫一个特定员工。这是我遇到问题的一个,因为它没有返回任何记录。 sp应该返回记录中的所有字段,因为这是来自雇员的select *,其中employeeid = empid;
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;



你们每个.NET方法都有一个单独的sp吗?

Do you have a separate sp for each .NET method, too?


这篇关于如何在gridview中只获取一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆