Error : “Fill: SelectCommand.Connection property has not been initialized.”

后端 未结 4 1646
鱼传尺愫
鱼传尺愫 2021-02-07 04:58

im getting this error while trying to connect a mysql database to an editor, here is the code behind:

protected void Button1_Click(object sender, EventArgs e)
{
         


        
相关标签:
4条回答
  • 2021-02-07 05:21

    Had this same error and simply just forgot the connection in the SQL string as mentioned above. Just needed to add con after the comma.

    0 讨论(0)
  • 2021-02-07 05:30

    Try This

    MySqlCommand cmd = new MySqlCommand("SELECT tes FROM ins",conn);
    

    or

    MySqlCommand cmd = new MySqlCommand("SELECT tes FROM ins");
    cmd.Connection=conn;
    
    0 讨论(0)
  • 2021-02-07 05:34

    I got also this problem. after search the problem found that the object of connection that i have provide SqlDataAdapter is not Initialize so the connection passed as null

    0 讨论(0)
  • 2021-02-07 05:35

    Change the line

    MySqlCommand cmd = new MySqlCommand("SELECT tes FROM ins");
    

    To

    MySqlCommand cmd = new MySqlCommand("SELECT tes FROM ins", conn);
    

    And it should work.

    Alternatively assign conn to the cmd.Connection property.

    The problem with your code is that you never assign a connection to the command, hence the error saying that the connection is not initialized.

    0 讨论(0)
提交回复
热议问题