跳转形式无法正常工作

时间:2012-05-04 13:57:46

标签: c# winforms sqlconnection

这是this previous one.

的相关问题

Bacasically我有两种形式,我想从第一种形式跳到第二种形式。 第一种形式的代码。

public partial class Main : Form
{
    public Main()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Edit_Metric Edit_Metric = new Edit_Metric();
        Edit_Metric.Show();
    }

}

第二种形式:

public partial class Edit_Metric : Form
{
    BindingSource bsource = new BindingSource();
    DataSet ds = new DataSet();
    private SqlDataAdapter da;
    public Edit_Metric()
    {
        InitializeComponent();
    }
    private string connString = ConfigurationManager.ConnectionStrings["QISConnectionString"].ConnectionString;

    private void Edit_Metric_Load(object sender, EventArgs e)
    {
        dgv.EditMode = DataGridViewEditMode.EditOnKeystroke;
        DataGridViewButtonColumn EditColumn = new DataGridViewButtonColumn();
        EditColumn.Text = "Edit";
        EditColumn.Name = "Edit";
        EditColumn.DataPropertyName = "Edit";
        EditColumn.DisplayIndex = 0;
        EditColumn.UseColumnTextForButtonValue = true;
        DataGridViewButtonColumn DelColumn = new DataGridViewButtonColumn();
        DelColumn.Text = "Delete";
        DelColumn.Name = "Delete";
        DelColumn.DataPropertyName = "Delete";
        DelColumn.DisplayIndex = 1;
        DelColumn.UseColumnTextForButtonValue = true;
        dgv.Columns.Add(EditColumn);
        dgv.Columns.Add(DelColumn);

        using (SqlConnection conn = new SqlConnection("connString"))
        {
            conn.Open();
            // data query, display data in a datagridview.
        }

我的问题是:代码何时到达

         using (SqlConnection conn = new SqlConnection("connString"))

下一步代码立即转到

的第一个表格
        Edit_Metric.Show();

它永远不会转到第二种形式的代码

         conn.Open();

由于

1 个答案:

答案 0 :(得分:0)

如果它不是拼写错误,您正在尝试使用字符串“connString”而不是上面的“QISConnectionString”中的var connString打开连接

我确定你想写

using (SqlConnection conn = new SqlConnection(connString))