MySQL and C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Bear

    MySQL and C#

    Has anyone successfully used MySQL with C#?

    I'm having problems using the Update command


    Here is the code snippet. I am able to connect to the database. However when I try to update the database with the changes in the dataset I get the following error:

    An unhandled exception of type 'System.Invalid OperationExcept ion' occurred in system.data.dll
    Additional information: Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information.

    public void setupConnection ()
    {
    conString="Prov ider=MySQLProv; Data Source=wedtest; SERVER=localhos t;DB=wedtest;UI D=admin;PWD=pas sword;PORT=3306 ";

    myConnection=ne w OleDbConnection (conString) ;

    string_sql="sel ect * from Budget";

    myDataSet = new DataSet();

    myConnection.Op en() ;

    if(myConnection .State==Connect ionState.Open)

    {

    Console.WriteLi ne("Connection made");

    }

    myOleDbAdapter = new OleDbDataAdapte r(string_sql,my Connection);

    myOleDbAdapter. Fill(myDataSet, "Budget") ;

    dataGrid1.DataS ource = myDataSet.Defau ltViewManager;


    myCommandBuilde r=new OleDbCommandBui lder(myOleDbAda pter);

    }

    public void updateRecord()

    {

    // Get all of the updated rows and update the datastore

    updatedRows = myDataSet.GetCh anges(System.Da ta.DataRowState .Modified);

    if (((updatedRows) != (null)))

    {

    myOleDbAdapter. Update(updatedR ows,"Budget");

    }

    }


    An unhandled exception of type 'System.Invalid OperationExcept ion' occurred in system.data.dll
    Additional information: Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information.
  • Alvin Bruney

    #2
    Re: MySQL and C#

    Try writing a straight query from the command object. I know this works
    public static void Execute(string sql)

    {

    using(OleDbConn ection cn = new OleDbConnection (_connString))

    {

    cn.Open();

    //Set sql as your insert,update or delete statement.

    using(OleDbComm and cmd = new OleDbCommand(sq l,cn))

    {

    cmd.ExecuteNonQ uery();

    }

    }

    }


    --
    Regards,
    Alvin Bruney
    Got tidbits? Get it here...

    "The Bear" <buck_roggers@h otmail.com> wrote in message news:a6gNb.351$ XZ.24225@news20 .bellglobal.com ...
    Has anyone successfully used MySQL with C#?

    I'm having problems using the Update command


    Here is the code snippet. I am able to connect to the database. However when I try to update the database with the changes in the dataset I get the following error:

    An unhandled exception of type 'System.Invalid OperationExcept ion' occurred in system.data.dll
    Additional information: Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information.

    public void setupConnection ()
    {
    conString="Prov ider=MySQLProv; Data Source=wedtest; SERVER=localhos t;DB=wedtest;UI D=admin;PWD=pas sword;PORT=3306 ";

    myConnection=ne w OleDbConnection (conString) ;

    string_sql="sel ect * from Budget";

    myDataSet = new DataSet();

    myConnection.Op en() ;

    if(myConnection .State==Connect ionState.Open)

    {

    Console.WriteLi ne("Connection made");

    }

    myOleDbAdapter = new OleDbDataAdapte r(string_sql,my Connection);

    myOleDbAdapter. Fill(myDataSet, "Budget") ;

    dataGrid1.DataS ource = myDataSet.Defau ltViewManager;


    myCommandBuilde r=new OleDbCommandBui lder(myOleDbAda pter);

    }

    public void updateRecord()

    {

    // Get all of the updated rows and update the datastore

    updatedRows = myDataSet.GetCh anges(System.Da ta.DataRowState .Modified);

    if (((updatedRows) != (null)))

    {

    myOleDbAdapter. Update(updatedR ows,"Budget");

    }

    }


    An unhandled exception of type 'System.Invalid OperationExcept ion' occurred in system.data.dll
    Additional information: Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information.

    Comment

    Working...