Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从VB.NET到C#在代码隐藏中向SQL数据源发送参数_C#_Vb.net_Parameters_Code Behind - Fatal编程技术网

从VB.NET到C#在代码隐藏中向SQL数据源发送参数

从VB.NET到C#在代码隐藏中向SQL数据源发送参数,c#,vb.net,parameters,code-behind,C#,Vb.net,Parameters,Code Behind,由于不了解C#,谁能帮我把这段vb代码翻译成C#。我试过很多在线转换器,但都没用。需要一个真正的专家…我正在尝试将参数从代码隐藏发送到SQL数据源。这里有双语的吗 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 I

由于不了解C#,谁能帮我把这段vb代码翻译成C#。我试过很多在线转换器,但都没用。需要一个真正的专家…我正在尝试将参数从代码隐藏发送到SQL数据源。这里有双语的吗

    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

如果您在已编译的二进制文件上使用.NET Reflector,它将为您将其反编译为C。 但是,请注意,您需要为click on button1添加事件处理程序。 比如:

Button1.click += Button1_Click;
另一个让我困惑的问题是,为什么要清除循环中的参数列表? 是不是应该在你开始循环之前

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;
    }
}
参数搜索框_par=New Parameter();
受保护的无效按钮1\u单击(对象发送者,System.EventArgse As){
整数整数计数;
字符串searchTxt=SearchBox.Text;
字符串[]arrText=Split(searchTxt);
对于(intCount=0;intCount
以下是最终更新的代码,它运行良好。。。。谢谢大家的提示

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;        }
}
使用系统;
使用System.Web;
使用System.Web.Mvc;
使用System.Web.UI.WebControl;
命名空间标识2_0
{  
公共部分类默认值:System.Web.UI.Page
{
受保护的无效SearchBoxButton_单击(对象发送者,System.EventArgs e)
{
参数搜索框_par=新参数();
字符串searchTxt=SearchBox.Text;
字符串[]arrText=searchTxt.Split();
searchBox_par.Name=“IDTextBox1”;
searchBox_par.Type=TypeCode.String;
for(int-int-count=0;int-count

}

谢谢您的回答。但是我得到了以下错误:1。名称拆分在当前上下文中不存在。2.找不到类型参数。3.数组不包含长度的定义。有什么帮助吗?对不起,翻译在飞行中没有注意到一些事情。1.字符串[]arrText=Split(searchTxt);应为字符串[]arrText=searchTxt.Split(“”);2.类型参数-您可能需要将Imports语句转换为Using语句。它可能是System.Data名称空间或类似名称空间的一部分。3.试试长度而不是长度。谢谢。越来越近。。。。仍然找不到类型参数。我会在一分钟内发布整个代码…真奇怪。参数应该在System.Web.UI.WebControl.Parameter命名空间中,至少据我所知是这样。也许最好试试.NET Reflector,看看它能给你带来什么。@Zohar说是的,System.Web.UI.WebControl不见了。现在代码运行良好。我将SqlDataSource3.SelectParameters.Clear()移动到循环外部,但它抛出了一个错误,即该参数已声明。“Split”调用不正确-使用字符串[]arrText=searchTxt.Split(“”);此外,正如Zohar提到的,您需要事件wireup(Button1.Click+=Button1\u Click;)