468,512 Members | 1,477 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

executenonquery problem in c#.net

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
1 1782
Rabbit
12,513 Expert Mod 8TB
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.

Similar topics

2 posts views Thread by Mark | last post: by
1 post views Thread by Mark | last post: by
5 posts views Thread by Paul Aspinall | last post: by
1 post views Thread by Matthew Louden | last post: by
reply views Thread by johnnymack0730 | last post: by
2 posts views Thread by jdb | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.