简体   繁体   English

VB.NET to C#将参数发送到后面的代码中的SQL数据源

[英]VB.NET to C# Sending parameters to an SQL datasource in code behind

Being ignorant about C#, can anyone help me translate this vb code to C#. 对C#一无所知,任何人都可以帮我翻译这个vb代码到C#。 I tried many on-line converters but they are useless. 我试过很多在线转换器,但它们没用。 Need a real expert.....I'm trying to send parameters from code behind to an SQL datasource. 需要一个真正的专家.....我正在尝试从后面的代码发送参数到SQL数据源。 Any bilingual in here: 在这里任何双语:

    Dim searchBox_par As New Parameter()

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click


    Dim intCount As Integer
    Dim searchTxt = SearchBox.Text
    Dim arrText = Split(searchTxt)


    For intCount = 0 To UBound(arrText)

        searchBox_par.Name = "IDTextBox1"
        searchBox_par.Type = TypeCode.String
        searchBox_par.DefaultValue = arrText(intCount)

        SqlDataSource3.SelectParameters.Clear()
        SqlDataSource3.SelectParameters.Add(searchBox_par)
        GridView2.Visible = True


    Next

End Sub

It should look somthing like this. 看起来应该是这样的。 However, note that you need to add the event handler for click on button1. 但是,请注意,您需要添加事件处理程序以单击button1。 something like: 就像是:

Button1.click += Button1_Click;

something else that puzzles me, is why do you clear the parameters list inside the loop? 令我困惑的其他东西,为什么你清除循环内的参数列表? Shouldn't it be before you start the loop? 不应该在你开始循环之前吗?

Parameter searchBox_par = New Parameter();

protedted void Button1_Click(object sender, System.EventArgse As) {

    Integer intCount;
    string searchTxt = SearchBox.Text;
    string[] arrText = Split(searchTxt);

    For(int intCount = 0; intCount < arrText.length; intCount++) {

        searchBox_par.Name = "IDTextBox1";
        searchBox_par.Type = TypeCode.String;
        searchBox_par.DefaultValue = arrText[intCount];

        SqlDataSource3.SelectParameters.Clear();
        SqlDataSource3.SelectParameters.Add(searchBox_par);
        GridView2.Visible = true;
    }
}

Here is the final updated code that works well.... Thank you all for your tips! 这是最终更新的代码,运行良好....谢谢大家的提示!

using System;
using System.Web;
using System.Web.Mvc;
using System.Web.UI.WebControls;
namespace Identity2_0
{  
public partial class Default : System.Web.UI.Page
{
     protected void SearchBoxButton_Click(object sender, System.EventArgs e)
    {
        Parameter searchBox_par = new Parameter();
        string searchTxt = SearchBox.Text;
        string[] arrText = searchTxt.Split();
        searchBox_par.Name = "IDTextBox1";
        searchBox_par.Type = TypeCode.String; 
        for (int intCount = 0; intCount < arrText.Length; intCount++)
        {
            SqlDataSource1.SelectParameters.Clear(); 
            searchBox_par.DefaultValue = arrText[intCount];
            SqlDataSource1.SelectParameters.Add(searchBox_par);
        }

         GridView1.Visible = true;        }
}

} }

如果在编译的二进制文件上使用.NET Reflector,它会将它反编译为C#。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM