VB.net到C#.net转换 [英] VB.net to C#.net Convertion

查看:74
本文介绍了VB.net到C#.net转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以将此代码转换为C#。我在数据库中选择一个整数。

Anyone can convert this code to C#. I'm selecting a integer in database.

Dim strsql2A As String = "SELECT TOTAL FROM employee WHERE ACCTNUM = '" & TextBox_Account.Text & "'"
                Dim txcda2A As MySqlDataAdapter = New MySqlDataAdapter(strsql2A, conn)
                Dim txcds2A As DataSet = New DataSet
                txcda2A.Fill(txcds2A, "employee")
                Dim txcdt2A As DataTable = txcds2A.Tables("employee")

                Dim row2A As DataRow

                For Each row2A In txcdt2A.Rows

                    If row2A("TOTAL") Is System.DBNull.Value Then 
TextBox_Total.Text = "0"
                    Else
                        TextBox_Total.Text = row2A("TOTAL")
                    End If

                Next row2A

推荐答案





这应该有效:

Hi,

This should work:
string strsql2A = "SELECT TOTAL FROM employee WHERE ACCTNUM = '" + TextBox_Account.Text + "'";
MySqlDataAdapter txcda2A = new MySqlDataAdapter(strsql2A, conn);
DataSet txcds2A = new DataSet();
txcda2A.Fill(txcds2A, "employee");
DataTable txcdt2A = txcds2A.Tables["employee"];

DataRow row2A = null;

foreach (DataRow row2A_loopVariable in txcdt2A.Rows)
 {
	row2A = row2A_loopVariable;

	if (object.ReferenceEquals(row2A["TOTAL"], System.DBNull.Value)) {
		TextBox_Total.Text = "0";
	} else {
		TextBox_Total.Text = row2A["TOTAL"];
	}

}





您可以在这里在线转换:

http://www.developerfusion.com/tools/convert/vb-to-csharp/ [ ^ ]



希望这有帮助!! :)



问候,

Praneet



You can convert it online here:
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]

Hope this helps !! :)

Regards,
Praneet


您可以将任何VB.NET代码转换为C#反之亦然。有许多在线工具,但使用基于反编译的离线工具然后用另一种语言编译可以实现最佳精度。使用开源ILSpy,结果代码的质量非常好。



对于链接,请参阅我的过去的答案编码解释,C#到VB.NET [ ^ ]。



祝你好运,

-SA
You can convert any VB.NET code to C# and visa versa automatically. There is a number of on-line tools, but the best accuracy can be achieved using the off-line tools based on decompilation and then compilation in another language. The quality of resulting code is amazingly good with open-source ILSpy.

For the links, please see my past answer Code Interpretation, C# to VB.NET[^].

Good luck,
—SA


if(Com.Connection.State == ConnectionState.Closed)

{

Com.Connection.Open();

}



Com.CommandText =SELECT ITEM_CODE FROM stock WHERE DESCRIPTIO ='+ comboBox_Supp2.Text +';

MySqlDataAdapter txcda2A = new MySqlDataAdapter(Com.CommandText,Com.Connection );

DataSet txcds2A = new DataSet();

txcda2A.Fill(txcds2A,stock);

DataTable txcdt2A = txcds2A.Tables [stock];



DataRow row2A = null;



foreach(txcdt2A.Rows中的DataRow row2A_loopVariable)

{

row2A = row2A_loopVariable;



if(object.ReferenceEquals(row2A [ITEM_CODE],System.DBNull.Value))

{

textBox_Bal2.Text =0;

}

else

{

textBox_Bal2.Text = row2A [ ITEM_CODE];

}



}





我在这段代码上有错误。 无法隐式地将类型'对象'转换为'字符串'。存在显式转换(您是否错过了演员?)
if (Com.Connection.State == ConnectionState.Closed)
{
Com.Connection.Open();
}

Com.CommandText = "SELECT ITEM_CODE FROM stock WHERE DESCRIPTIO = '" + comboBox_Supp2.Text + "'";
MySqlDataAdapter txcda2A = new MySqlDataAdapter(Com.CommandText, Com.Connection);
DataSet txcds2A = new DataSet();
txcda2A.Fill(txcds2A, "stock");
DataTable txcdt2A = txcds2A.Tables["stock"];

DataRow row2A = null;

foreach (DataRow row2A_loopVariable in txcdt2A.Rows)
{
row2A = row2A_loopVariable;

if (object.ReferenceEquals(row2A["ITEM_CODE"], System.DBNull.Value))
{
textBox_Bal2.Text = "0";
}
else
{
textBox_Bal2.Text = row2A["ITEM_CODE"];
}

}


I have an error on this code. "Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)"


这篇关于VB.net到C#.net转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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