C#转vb.net代码,大哥,帮忙
using System;using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection myconn = new SqlConnection("server=.\\SQLEXPRESS;database=PROGRESSDATA;uid=sa;pwd=179113");
SqlDataAdapter mysqldata = new SqlDataAdapter("select PJNM , PHNM, WorkID,Date,Pprogress,Rprogress from WorkDetail,Project,Phase where WorkDetail.PJID=Project.PJID and Phase.PHID=WorkDetail.PHID", myconn);
DataSet ds=new DataSet();
mysqldata.Fill(ds, "WorkDetail");
DataView aDataView = ds.Tables["WorkDetail"].DefaultView;
jb_tab.GridLines = GridLines.Both;
jb_tab.BorderStyle = BorderStyle.Solid;
jb_tab.BorderWidth = 1;
jb_tab.CellPadding = 3;
jb_tab.CellSpacing = 0;
jb_tab.Width = 300;
jb_tab.BorderColor = Color.FromArgb(20,120,235);
foreach( DataRowView aRow in aDataView)
{
TableRow aTableRow = new TableRow();
TableCell Cell_zzzh = new TableCell();
TableCell Cell_xb = new TableCell();
TableCell Cell_sl= new TableCell();
TableCell Cell_date = new TableCell();
TableCell Cell_Pp = new TableCell();
TableCell Cell_Rp = new TableCell();
Cell_zzzh.Text = aRow["PJNM"].ToString();
Cell_xb.Text = aRow["PHNM"].ToString();
Cell_sl.Text = aRow["WorkID"].ToString();
Cell_date.Text = aRow["Date"].ToString();
Cell_Pp.Text = aRow["Pprogress"].ToString();
Cell_Rp.Text = aRow["Rprogress"].ToString();
aTableRow.Cells.Add(Cell_zzzh);
aTableRow.Cells.Add(Cell_xb);
aTableRow.Cells.Add(Cell_sl);
aTableRow.Cells.Add(Cell_date);
aTableRow.Cells.Add(Cell_Pp);
aTableRow.Cells.Add(Cell_Rp);
jb_tab.Rows.Add(aTableRow);
}
/***开始合并单元格***/
int iRows; //DataTable的行数
int iColumns; //DataTable的列数
iRows=jb_tab.Rows.Count;
iColumns=2;
string strTmp=null; //临时变量保存单元格值
int iRowSpan=1; //拉伸到几个行高
int iRowNo=0; //正在拉伸的行号
int iColNo=0; //正在拉伸的列号
for (int i=0;i<iColumns;i++) //历遍绑定到表的所有列
{
strTmp="";
for (int j=0;j<iRows;j++) //历遍绑定到表的所有行(单元格)
{
if (strTmp==jb_tab.Rows[j].Cells[i].Text.ToString().Trim()) //将临时变量与指定单元格的制进行比较
{
iRowSpan=iRowSpan+1;
jb_tab.Rows[j].Cells[i].Visible=false; //隐藏当前单元格
jb_tab.Rows[iRowNo].Cells[iColNo].RowSpan=iRowSpan; //上面的单元格在纵向改变为n个单元格的高度
}
else
{
iRowNo=j;
iColNo=i;
iRowSpan=1;
strTmp=jb_tab.Rows[j].Cells[i].Text.ToString().Trim(); //将当前单元格的值赋给临时变量
}
}
}
/***合并完毕***/
}
}
--------------------编程问答-------------------- 网上有现成的C# To VB的convertor
软件 找找,一转换就可以了 --------------------编程问答-------------------- Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Collections
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Drawing
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim myconn As New SqlConnection("server=.\SQLEXPRESS;database=PROGRESSDATA;uid=sa;pwd=179113")
Dim mysqldata As New SqlDataAdapter("select PJNM , PHNM, WorkID,Date,Pprogress,Rprogress from WorkDetail,Project,Phase where WorkDetail.PJID=Project.PJID and Phase.PHID=WorkDetail.PHID", myconn)
Dim ds As New DataSet
mysqldata.Fill(ds, "WorkDetail")
Dim aDataView As DataView = ds.Tables("WorkDetail").DefaultView
jb_tab.GridLines = GridLines.Both
jb_tab.BorderStyle = BorderStyle.Solid
jb_tab.BorderWidth = 1
jb_tab.CellPadding = 3
jb_tab.CellSpacing = 0
jb_tab.Width = 300
jb_tab.BorderColor = Color.FromArgb(20, 120, 235)
For Each aRow As DataRowView In aDataView
Dim aTableRow As New TableRow
Dim Cell_zzzh As New TableCell
Dim Cell_xb As New TableCell
Dim Cell_sl As New TableCell
Dim Cell_date As New TableCell
Dim Cell_Pp As New TableCell
Dim Cell_Rp As New TableCell
Cell_zzzh.Text = aRow("PJNM").ToString()
Cell_xb.Text = aRow("PHNM").ToString()
Cell_sl.Text = aRow("WorkID").ToString()
Cell_date.Text = aRow("Date").ToString()
Cell_Pp.Text = aRow("Pprogress").ToString()
Cell_Rp.Text = aRow("Rprogress").ToString()
aTableRow.Cells.Add(Cell_zzzh)
aTableRow.Cells.Add(Cell_xb)
aTableRow.Cells.Add(Cell_sl)
aTableRow.Cells.Add(Cell_date)
aTableRow.Cells.Add(Cell_Pp)
aTableRow.Cells.Add(Cell_Rp)
jb_tab.Rows.Add(aTableRow)
Next
'**开始合并单元格**
Dim iRows As Integer
'DataTable的行数
Dim iColumns As Integer
'DataTable的列数
iRows = jb_tab.Rows.Count
iColumns = 2
Dim strTmp As String = Nothing
'临时变量保存单元格值
Dim iRowSpan As Integer = 1
'拉伸到几个行高
Dim iRowNo As Integer = 0
'正在拉伸的行号
Dim iColNo As Integer = 0
For i As Integer = 0 To iColumns - 1
'正在拉伸的列号
'历遍绑定到表的所有列
strTmp = ""
For j As Integer = 0 To iRows - 1
'历遍绑定到表的所有行(单元格)
If strTmp = jb_tab.Rows(j).Cells(i).Text.ToString().Trim() Then
'将临时变量与指定单元格的制进行比较
iRowSpan = iRowSpan + 1
jb_tab.Rows(j).Cells(i).Visible = False
'隐藏当前单元格
'上面的单元格在纵向改变为n个单元格的高度
jb_tab.Rows(iRowNo).Cells(iColNo).RowSpan = iRowSpan
Else
iRowNo = j
iColNo = i
iRowSpan = 1
'将当前单元格的值赋给临时变量
strTmp = jb_tab.Rows(j).Cells(i).Text.ToString().Trim()
End If
Next
Next
'**合并完毕**
End Sub
End Class --------------------编程问答-------------------- 强! --------------------编程问答-------------------- http://www.developerfusion.com/tools/convert/csharp-to-vb/
这个网站是专门进行C#和VB代码的转换的,转换很智能,比动软代码生成器里的转换程序智能的多
你可以用一下,很好用的
补充:.NET技术 , C#