|
nitish_07 wrote: when it comes to calling that procedure it throws an error
you have shown the SP and the exception, that is fine; yet you didn't show the calling code, where the problem could well be...
|
|
|
|
|
after the last cmd.executenonquery it throws an error....
|
|
|
|
|
nitish_07 wrote: it throws an error
which suggests it is wrong, so show the code.
|
|
|
|
|
I have shown the whole code in my first post.....What else do u want??
|
|
|
|
|
sorry I looked over it.
your parameters have identifiers staring with ?, your SQL doesn't use '?' at all. I doubt that is correct.
BTW: always look at (and show us) the full exception (i.e. exception.ToString), not just the one-line message.
|
|
|
|
|
nitish_07 wrote: cmd.CommandText = "add_emp;";
I do not think this is right. Should it not be
nitish_07 wrote: cmd.CommandText = "add_emp";
Extra semicolon.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
I have corrected it but it didnt solve my problem..
|
|
|
|
|
Sooo, overall, your creating a table to hold employee data, which is usually a permanent table in a database, and creating the stored procedure to add an employee to this table, AND calling the procedure to add an employee to this table, ALL IN ONE METHOD??
Your database should be created at install-time, not runtime. Your code should only be calling the stored procedure. I have to ask why you're doing it this way??
|
|
|
|
|
Actually the thing is I am testing it...I am developing mysql query browser. so when i am calling sp at run time then also i m getting same error...so i have searched on net c# code for calling sp..and i have got this code but when i implemented this then it throws the same error.....
|
|
|
|
|
Some small changes:
cmd.CommandText = "add_emp(@fname, @lname, @bday)";
Then use the parameters prefixed with @ instead of ? :
cmd.Parameters.AddWithValue("@lname", "Jones");
|
|
|
|
|
ya I have done this....bt nothing happened...same error shows....
ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.77-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'add_emp(@fname, @lname, @bday)' at line 1
|
|
|
|
|
I looked again at your code, and now I'm wondering maybe something is wrong about the bday type (DATETIME,DATE) and the DATE function; so I'd recommend you leave it out till you get the SP working, then add it back in and fix it if necessary.
Note 1: I also saw your first Con.Open() was commented...
Note 2: and you do check the SP for existence before creating one, but not the table itself.
|
|
|
|
|
I have deleted the bday option but again same issue.....and con.open() is not an issue....
and i have checked sp for its existence....no issue....
|
|
|
|
|
i think as keyword missing.
First exexcute the block in sqlserver then try into fron tend.
But best practice is using sp
|
|
|
|
|
I have to create mysql stored function from c#.net.
User will create the function at run time and i have to pass this string in odbc command like this...
rt.Text = "CREATE FUNCTION" +" "+ "`" + node + "`" +" "+ "." +" "+"'"+textBox1.Text +"'"+" "+" ()"+" "+ "@RETURNS INT"+" @BEGIN@END;";
rt.Text = rt.Text.Replace("@", System.Environment.NewLine);
OdbcCommand cmd = new OdbcCommand(rt.text, cn);
cmd.CommandText = rt1.text;
cmd.ExecuteNonQuery();
But it shows that You have syntax error.Check the manual that correspond to your mysql document...so plz tell me what is the problem.....??
|
|
|
|
|
nitish_07 wrote: But it shows that You have syntax error
If you encounter an error or an exception, than paste the entire thing into your post. I'm guessing that it's an exception that's thrown on ExecuteNonQuery as your Sql-statement is malformed. It's also damn hard to read.
Concatenating strings is fun, but you don't want to overdo it. The code below is allowed too;
rt.Text = "CREATE FUNCTION `" + node + "` . '"+textBox1.Text +"' () "+
"@RETURNS INT @BEGIN@END;";
rt.Text = rt.Text.Replace("@", System.Environment.NewLine);
OdbcCommand cmd = new OdbcCommand(rt.text, cn);
cmd.CommandText = rt1.text;
cmd.ExecuteNonQuery();
I'm going to guess again that it's the `-character that's not being recognized, and that it should be replace with a '. Further, you'd want a Debug.Print(rt.Text) so that you can easily validate the syntax of your query.
Hope this helps
Bastard Programmer from Hell
|
|
|
|
|
Error is this
System.Data.Odbc.OdbcException: ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.77-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''df' ()
RETURNS INT
BEGIN
return 1;
END' at line 1
and string is i.e rt.text=
"CREATE FUNCTION `userdb` . 'df' () \nRETURNS INT \nBEGIN\nreturn 1;\nEND;"
|
|
|
|
|
I think the error goes away if you change the type of quote in there;
"CREATE FUNCTION 'userdb'.'df'() \nRETURNS INT \nBEGIN\nreturn 1;\nEND;"
Again, the character ` cannot be used instead of the character ' .
Bastard Programmer from Hell
|
|
|
|
|
ok I am trying...actually this is written in the orginal mysqlbrowser when i create the fucntion
CREATE FUNCTION `userdb`.`gh` () RETURNS INT
BEGIN
return 1;
END$$
so i think this is also ` not ' ???
|
|
|
|
|
Thanks man done....
|
|
|
|
|
First, using string concatentation to build a query is just plain bad practice. Especially when you are doing with with consecutive, individual characters. It makes your code impossible to read and debug accurately.
Oh, and your call to Replace is not needed at all. Using the @ character in a string to denote new lines in an SQL statement is a bad idea since SQL parameters usually start with that character.
A better method is to use String.Format:
string queryString;
queryString = String.Format("CREATE FUNCTION '{0}'.'{1}'()\nRETURNS INT\nBEGIN\nEND;", node, functionName);
Now is your code easier to read, or is mine?
|
|
|
|
|
Yes you are right...Thanks man....If you could provide the solution for the problem which i posted some min ago....
|
|
|
|
|
Every one voted it down how can i remove it?
Ques was:- I am Trying to built the search box for my windows app that searches the data from the database
Thanks
modified 15-Apr-12 9:27am.
|
|
|
|
|
You need to give some more detail about what this box will do and what part you are having trouble with. Putting your question into Google will give you some useful suggestions.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
|
|
|
|
|