By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

executenonquery problem in c#.net

P: 2
I'm having problem in executing non query sql statement. Bear in mind, I'm still new to .NET framework and MySQL. Here is my code.

Expand|Select|Wrap|Line Numbers
  1. private void Binding()
  2.         {
  3.             string connStr = "datasource=localhost;port=3306;username=root;password=root;";
  4.             conn = new MySqlConnection(connStr);
  5.             MySqlCommand command = conn.CreateCommand();
  6.             try
  7.             {
  8.                 string database = schemaForm.getData;
  9.                 dtable = new DataTable();
  10.                 bindingSource = new BindingSource(); ;
  11.  
  12.                     conn.Open();
  13.                     command.CommandText = "SELECT Metabolite_Name" +
  14.                                           "FROM " + database +
  15.                                           ".Metabolites WHERE"+
  16.                                           " MetaboliteID IN ('met1', 'met2');";
  17.                     command.ExecuteNonQuery();
  18.                     sqlData.SelectCommand = command;
  19.                     sqlData.Fill(dtable);
  20.                     bindingSource.DataSource = dtable;
  21.                     dbMetName.DataSource = dtable;
  22.                     dtable.Columns.Add("Metabolite Name");
  23.                     dbMetName.DataSource = dtable;
  24.                     conn.Close();        
  25.             }
  26.             catch (Exception ex)
  27.             {
  28.                 MessageBox.Show(ex.Message);
  29.             }
  30.         }
Passing value from getData form

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace DynamicSimulator_v2
  11. {
  12.     public partial class SchemaName : Form
  13.     {
  14.         private static string data;
  15.         public SchemaName()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void btnCancel_Click(object sender, EventArgs e)
  21.         {
  22.             this.Hide();
  23.         }
  24.  
  25.         private void btnOK_Click(object sender, EventArgs e)
  26.         {
  27.             data=txtDB.Text;
  28.             this.Hide();
  29.         }
  30.  
  31.         public string getData
  32.         {
  33.             set
  34.             {
  35.                 data = txtDB.Text;
  36.             }
  37.             get
  38.             {
  39.               return data;
  40.             }
  41.         }
  42.     }
  43. }
The error shows that my query is wrong. I pretty sure the query was right as I tested it on MySQL script. And I try to show in datagridview by the way
Oct 20 '13 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,347
Output the actual query string and you will see the problem that you have. You're missing a space between the column specification and the from clause.
Oct 21 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.