473,382 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 2123
Rabbit
12,516 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

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

Similar topics

2
by: Mark | last post by:
Hi, I have a sqlCommand object that I use to execute an SQL statement. I thought I could use the ExecuteNonQuery to test for the number of rows returned by the sql command but it does not seem to...
1
by: Mark | last post by:
It appears that you can only retrieve an Output parameter from a SQL Server stored procedure when using the ExecuteNonQuery of the SqlCommand class, and cannot use the ExecuteReader() method. In...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
5
by: Paul Aspinall | last post by:
Hi I have a Stored Proc in SQL server, which creates a record key when a record is created. I want to return the value back to my code, once the record has been created. I am using SQLHelper...
1
by: Matthew Louden | last post by:
I just tried to create a simple ASP.NET application to add record to the SQL Server database. However, it has run time error on Line 88: objCommand.ExecuteNonQuery() Any ideas?? Please help!!...
0
by: johnnymack0730 | last post by:
Hello - I am currently working on an asp.net application that needs to be able to update an access table using ExecuteNonQuery method. I have all the code setup, it runs, there are no errors...
4
by: MDW | last post by:
Hey all. I'm confused. I'm trying to add a single record into an Access 2000 database using ASP.Net. Here is the code: objConn = New OleDbConnection(strConnect) objConn.Open objCommand =...
2
by: jdb | last post by:
Hi, I am adding a record to the database using an ExecuteNonQuery, which adds without problem. Now after the record is added I run a method passing in some info as well as the curretnly opened...
3
by: keithb | last post by:
What can I put in a stored procedure to control what gets returned by command.ExecuteNonQuery()? I already tried this: param = comm.CreateParameter(); param.ParameterName = "@Success"; ...
2
by: TheSteph | last post by:
Hi I have a SQLCommand that do updates on a table. I have a loop where I set the parameters then I call ExecuteNonQuery. For . { . Set the SQLCommand's Params Values;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.