Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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
C# c中的SqlConnection错误索引0_C#_Sqlconnection - Fatal编程技术网

C# c中的SqlConnection错误索引0

C# c中的SqlConnection错误索引0,c#,sqlconnection,C#,Sqlconnection,在下面的代码中,当我尝试连接到连接字符串时,我看到了这个错误。这个错误出现了 初始化字符串的格式不符合从索引0开始的规范 我怎样才能修好它? 在下面的代码中,当我尝试连接到连接字符串时,我看到了这个错误。这个错误出现了 初始化字符串的格式不符合从索引0开始的规范 我怎样才能修好它 namespace InsertUserApp { public partial class Home : Form { class ComboItemExample {

在下面的代码中,当我尝试连接到连接字符串时,我看到了这个错误。这个错误出现了

初始化字符串的格式不符合从索引0开始的规范

我怎样才能修好它? 在下面的代码中,当我尝试连接到连接字符串时,我看到了这个错误。这个错误出现了

初始化字符串的格式不符合从索引0开始的规范

我怎样才能修好它

namespace InsertUserApp
{
    public partial class Home : Form
    {
        class ComboItemExample
        {
            public string DisplayString { get; set; }
            public string ConnectionString { get; set; }

            public override string ToString() { return DisplayString; }
        }
        private string connstring = "<default connection>";

        public Home()
        { 
            InitializeComponent();

            var srv1 = new ComboItemExample { DisplayString = "Srv1", ConnectionString = "Data Source=tcp:10.0.0.110;Initial Catalog=Database1;User ID=user;Password=pass;" };
            cmbSrv.Items.Add(srv1);

            var srv2 = new ComboItemExample { DisplayString = "Srv2", ConnectionString = "Data Source=tcp:10.1.0.11;Initial Catalog=Database2;User ID=user;Password=pass;" };
            cmbSrv.Items.Add(srv2);

            var srv3 = new ComboItemExample { DisplayString = "Srv3", ConnectionString = "Data Source=tcp:10.1.0.15;Initial Catalog=Database3;User ID=user;Password=pass" };
            cmbSrv.Items.Add(srv3);

        }


            private void txtID_TextChanged(object sender, EventArgs e)
    { 
            using (SqlConnection connection = new SqlConnection(connstring))
            {
                /*if (String.IsNullOrEmpty(txtID.Text))
                {
                    MessageBox.Show("Plotesoni fushat UnID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }
                else
                {*/
                SqlCommand command1 =
                new SqlCommand("select * from Table1 WHERE Tag = 'User' and UnId = '" + txtID.Text + "'", connection);
                SqlCommand command2 =
                new SqlCommand("select * from Table1 WHERE Tag = 'Pass' and UnId = '" + txtID.Text + "'", connection);
                SqlCommand command3 =
                new SqlCommand("select * from Table1 WHERE Tag = 'Shifra1' and UnId = '" + txtID.Text + "'", connection);
                SqlCommand command4 =
                SqlCommand command5 =
                new SqlCommand("select * from Table2 WHERE UnId = '" + txtID.Text + "'", connection);
                connection.Open();

                SqlDataReader read1 = command1.ExecuteReader();


                while (read1.Read())
                {
                    txtID.Text = (read1["UnId"].ToString());
                    txtUser.Text = (read1["Value"].ToString());

                }
                read1.Close();
                SqlDataReader read2 = command2.ExecuteReader();
                while (read2.Read())
                {
                    txtPass.Text = (read2["Value"].ToString());
                }
                read2.Close();
                SqlDataReader read3 = command3.ExecuteReader();
                while (read3.Read())
                {
                    txtOrg.Text = (read3["Value"].ToString());
                }
                read3.Close();
                SqlDataReader read5 = command5.ExecuteReader();
                while (read5.Read())
                {
                    txtgrp.Text = (read5["shifra1"].ToString());
                }
                read5.Close();
            }
        }


        }
    }
}

当我在互联网上回顾时,我认为问题在于这一行代码

有什么建议吗

var srv1 = new ComboItemExample { DisplayString = "Srv1", ConnectionString = "Data Source=tcp:10.0.0.110;Initial Catalog=Database1;User ID=user;Password=pass;" };
        cmbSrv.Items.Add(srv1);

那么,这就是连接时使用的连接字符串?另外,我现在要更改数据库上的密码,因为您已经在这里发布了它…{using SqlConnection connection=new SqlConnectionconnstring}而且用户名和密码只是示例,不是真实的