谁能帮我把这段vb.net代码转成c#的?万分感谢!!
'得到数据视图,参数为要排序的列PrivateFunctionGetDv(ByValstrSortAsString)AsDataView'定义数据库连接DimdvAsDa...
'得到数据视图,参数为要排序的列
Private Function GetDv(ByVal strSort As String) As DataView
'定义数据库连接
Dim dv As DataView
Dim CN As New SqlConnection()
Try
'初始化连接字符串
CN.ConnectionString = "data source=pmserver;
initial catalog=Northwind;persist security info=False;user id=sa;Password=sa;"
CN.Open()
'从NorthWind得到orders表的数据
Dim adp As SqlDataAdapter = New SqlDataAdapter("select * from orders", CN)
Dim ds As New DataSet()
adp.Fill(ds)
'得到数据视图
dv = ds.Tables(0).DefaultView
Catch ex As Exception
#If DEBUG Then
Session("Error") = ex.ToString()
Response.Redirect("../error.aspx") '跳转程序的公共错误处理页面
#End If
Finally
'关闭连接
CN.Close()
End Try
'排序
dv.Sort = strSort
Return dv
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
If Not IsPostBack Then
ViewState("strSort") = "orderid"
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End If
End Sub
'排序
Private Sub dgOrder_SortCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgOrder.SortCommand
dgOrder.CurrentPageIndex = 0
'得到排序的列
ViewState("strSort") = e.SortExpression.ToString()
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
'分页
Private Sub dgOrder_PageIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOrder.PageIndexChanged
'得到分页的页号
dgOrder.CurrentPageIndex = e.NewPageIndex
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
谢谢stainboy!!
http://www.pconline.com.cn/
还是搞不定呀,帮我看看我个网址,我想改成c#的,而且要实现他弹出的选中的行的哪个 展开
Private Function GetDv(ByVal strSort As String) As DataView
'定义数据库连接
Dim dv As DataView
Dim CN As New SqlConnection()
Try
'初始化连接字符串
CN.ConnectionString = "data source=pmserver;
initial catalog=Northwind;persist security info=False;user id=sa;Password=sa;"
CN.Open()
'从NorthWind得到orders表的数据
Dim adp As SqlDataAdapter = New SqlDataAdapter("select * from orders", CN)
Dim ds As New DataSet()
adp.Fill(ds)
'得到数据视图
dv = ds.Tables(0).DefaultView
Catch ex As Exception
#If DEBUG Then
Session("Error") = ex.ToString()
Response.Redirect("../error.aspx") '跳转程序的公共错误处理页面
#End If
Finally
'关闭连接
CN.Close()
End Try
'排序
dv.Sort = strSort
Return dv
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
If Not IsPostBack Then
ViewState("strSort") = "orderid"
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End If
End Sub
'排序
Private Sub dgOrder_SortCommand(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgOrder.SortCommand
dgOrder.CurrentPageIndex = 0
'得到排序的列
ViewState("strSort") = e.SortExpression.ToString()
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
'分页
Private Sub dgOrder_PageIndexChanged(ByVal source As Object,
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOrder.PageIndexChanged
'得到分页的页号
dgOrder.CurrentPageIndex = e.NewPageIndex
dgOrder.DataSource = GetDv(ViewState("strSort").ToString())
dgOrder.DataBind()
End Sub
谢谢stainboy!!
http://www.pconline.com.cn/
还是搞不定呀,帮我看看我个网址,我想改成c#的,而且要实现他弹出的选中的行的哪个 展开
2个回答
展开全部
//得到数据视图,参数为要排序的列
private DataView GetDv(string strSort)
{
//定义数据库连接
DataView dv;
SqlConnection CN = new SqlConnection();
try
{
//初始化连接字符串
CN.ConnectionString = "data source=pmserver;initial catalog=Northwind;persist security info=False;user id=sa;Password=sa;";
CN.Open();
//从NorthWind得到orders表的数据
SqlDataAdapter adp = new SqlDataAdapter("select * from orders", CN);
DataSet ds = new DataSet();
adp.Fill(ds);
//得到数据视图
dv = ds.Tables[0].DefaultView;
}
catch (Exception ex)
{
#if DEBUG
Session["Error"] = ex.ToString();
Response.Redirect("../error.aspx"); //跳转程序的公共错误处理页面
#endif
}
finally
{
//关闭连接
CN.Close();
}
//排序
dv.Sort = strSort;
return dv;
}
private void Page_Load(System.Object sender, System.EventArgs e)
{
if (! IsPostBack)
{
ViewState["strSort"] = "orderid";
dgOrder.DataSource = GetDv[ViewState["strSort"].ToString()];
dgOrder.DataBind();
}
}
//排序
private void dgOrder_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
dgOrder.CurrentPageIndex = 0;
//得到排序的列
ViewState["strSort"] = e.SortExpression.ToString();
dgOrder.DataSource = GetDv[ViewState["strSort"].ToString()];
dgOrder.DataBind();
}
//分页
private void dgOrder_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
//得到分页的页号
dgOrder.CurrentPageIndex = e.NewPageIndex;
dgOrder.DataSource = GetDv[ViewState["strSort"].ToString()];
dgOrder.DataBind();
}
可能会有点错误的,需要自己修改一下
private DataView GetDv(string strSort)
{
//定义数据库连接
DataView dv;
SqlConnection CN = new SqlConnection();
try
{
//初始化连接字符串
CN.ConnectionString = "data source=pmserver;initial catalog=Northwind;persist security info=False;user id=sa;Password=sa;";
CN.Open();
//从NorthWind得到orders表的数据
SqlDataAdapter adp = new SqlDataAdapter("select * from orders", CN);
DataSet ds = new DataSet();
adp.Fill(ds);
//得到数据视图
dv = ds.Tables[0].DefaultView;
}
catch (Exception ex)
{
#if DEBUG
Session["Error"] = ex.ToString();
Response.Redirect("../error.aspx"); //跳转程序的公共错误处理页面
#endif
}
finally
{
//关闭连接
CN.Close();
}
//排序
dv.Sort = strSort;
return dv;
}
private void Page_Load(System.Object sender, System.EventArgs e)
{
if (! IsPostBack)
{
ViewState["strSort"] = "orderid";
dgOrder.DataSource = GetDv[ViewState["strSort"].ToString()];
dgOrder.DataBind();
}
}
//排序
private void dgOrder_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
dgOrder.CurrentPageIndex = 0;
//得到排序的列
ViewState["strSort"] = e.SortExpression.ToString();
dgOrder.DataSource = GetDv[ViewState["strSort"].ToString()];
dgOrder.DataBind();
}
//分页
private void dgOrder_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
//得到分页的页号
dgOrder.CurrentPageIndex = e.NewPageIndex;
dgOrder.DataSource = GetDv[ViewState["strSort"].ToString()];
dgOrder.DataBind();
}
可能会有点错误的,需要自己修改一下
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询