当前位置:编程学习 > C#/ASP.NET >>

一个VBNET的小东西,移植动C#里,不懂C#啊



就是data里已经读出了数据,现在放一个按钮,根据TEXT里输入的内容查找跟DATA里的数据相匹配的,如果找到了就在后面LURU自如显示为“已录入” 如果在查找他,并且后面已经是"已录入"的话就提示已经查找过了(改为“已录入”的时候只要data里显示的改一下就好,数据库是不需要更改的)
下面是VBNET的代码
不过VBNET里我用的是datagridview
C#里我想用DATAGRID,后期可能要移动WINCE里,
大家帮我用C#写下这个功能号码,
用在线转换出来的完全牛头不搭马嘴啊
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim _dt As DataTable = DataGridView1.DataSource
        Dim _existrows() As DataRow = _dt.Select("chanpin='" & TextBox1.Text & "'")
        If _existrows.Length = 0 Then

            MsgBox("(没有该产品)")
        Else

            If Not IsDBNull(_existrows(0)("luru")) Then
                MsgBox("已经录入啦")
            Else
                _existrows(0)("luru") = "已录入"
            End If
        End If
    End Sub
--------------------编程问答-------------------- 这个其实很简单,我觉得多看几次VB代码读起来还是很通顺的,源于以前VB6?!也许吧,哈哈。。。
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim _dt As DataTable = DataGridView1.DataSource
DataTable _dt = DataGridView1.DataSource//VB转c#挪动一些位置就完成了
        Dim _existrows() As DataRow = _dt.Select("chanpin='" & TextBox1.Text & "'")
DataRow _existrows[] = _dt.Select("chanpin='" + TextBox1.Text + "'")
        If _existrows.Length = 0 Then
if(_existrows.Count() == 0)
            MsgBox("(没有该产品)")
        Else

            If Not IsDBNull(_existrows(0)("luru")) Then//这句检查字段非空
if(_existrows[0]["luru"] != null)
                MsgBox("已经录入啦")
            Else
                _existrows(0)("luru") = "已录入"
_existrows[0]["luru"] = "已录入"
            End If
        End If
    End Sub


哦,所有C#语句最后应加分号。 --------------------编程问答-------------------- DataRow _existrows[] = _dt.Select("chanpin='" + TextBox1.Text + "'")位置放错了
DataRow[] _existrows = _dt.Select("chanpin='" + TextBox1.Text + "'") --------------------编程问答--------------------

private void button2_Click(object sender, EventArgs e)
        {
            Dim _dt As DataTable = DataGridView1.DataSource;
DataTable _dt = DataGridView1.DataSource;//VB转c#挪动一些位置就完成了
        Dim _existrows() As DataRow = _dt.Select("chanpin='" & TextBox1.Text & "'");
DataRow[] _existrows = _dt.Select("chanpin='" + TextBox1.Text + "'");
        If _existrows.Length = 0 Then ;
if(_existrows.Count() == 0);
            MsgBox("(没有该产品)");
        Else;
 
            If Not IsDBNull(_existrows(0)("luru")) Then;  //这句检查字段非空
if(_existrows[0]["luru"] != null);
                MsgBox("已经录入啦");
            Else
                _existrows(0)("luru") = "已录入";
_existrows[0]["luru"] = "已录入";
            End If;
        End If;
        }


报错很多啊  大哥 --------------------编程问答-------------------- --------------------编程问答--------------------
引用 3 楼 jainkai 的回复:

private void button2_Click(object sender, EventArgs e)
        {
            Dim _dt As DataTable = DataGridView1.DataSource;
DataTable _dt = DataGridView1.DataSource;//VB转c#挪动一些位置就完成了
        Dim _existrows() As DataRow = _dt.Select("chanpin='" & TextBox1.Text & "'");
DataRow[] _existrows = _dt.Select("chanpin='" + TextBox1.Text + "'");
        If _existrows.Length = 0 Then ;
if(_existrows.Count() == 0);
            MsgBox("(没有该产品)");
        Else;
 
            If Not IsDBNull(_existrows(0)("luru")) Then;  //这句检查字段非空
if(_existrows[0]["luru"] != null);
                MsgBox("已经录入啦");
            Else
                _existrows(0)("luru") = "已录入";
_existrows[0]["luru"] = "已录入";
            End If;
        End If;
        }


报错很多啊  大哥


用VB.NET编译,用ILSpy打开,反编译,下拉语言选择C#,搞定。ILSpy基于编译而不是简单的文本匹配,转换能力要比在线的高很多。 --------------------编程问答-------------------- 人家给你写的是VB程序啊,你自己翻译成c#呗 --------------------编程问答-------------------- private Button4_Click(object sender, EventArgs e) //需要手工写 Button4.Click += Button4_Click;
        DataTable _dt = DataGridView1.DataSource
        DataRow[] _existrows() = _dt.Select("chanpin='" + TextBox1.Text + "'")
        if (_existrows.Length == 0)
        {
            MessageBox.Show("(没有该产品)");
        }
        else
        {
            if (!(_existrows[0]["luru"] == DbNull))
            {
                MessageBox.Show("已经录入啦");
            }
            else
            {
                _existrows[0]["luru"] = "已录入";
            }
        }
    }

手工转的,仅供参考。 --------------------编程问答-------------------- 还是不懂 、、

转换也不行,。,。。


点解啊
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,