|
Actually, I need to add Code 128 barcodes printing function in my project
|
|
|
|
|
|
This winforms barcode generator support Code 128 as well, you may try it.
|
|
|
|
|
Marked as spam
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
private void rtb_leave(object sender, EventArgs e)
{
Class1.query = rtb.Text;
}
private void InitializeComponent()
{
this.rtb = new System.Windows.Forms.RichTextBox();
this.rtb.Leave += new System.EventHandler(this.rtb_leave);
}
I have done this coding...But leave event is not working..what is the problem??
|
|
|
|
|
if this is actual code, then:
1) it is ugly (Class1 is not a good name for a class; a property should be CamelCased);
2) you can't leave a Control that isn't part of some Container (such as a Form), and hence invisible.
and if it isn't we can not help you as actual code is required.
|
|
|
|
|
thanks...somehow i managed with other logic.....
|
|
|
|
|
OdbcCommand cmd = new OdbcCommand();
try
{
cmd.Connection = cn;
cmd.CommandText = "use userdb";
cmd.ExecuteNonQuery();
cmd.CommandText = "DROP PROCEDURE IF EXISTS add_emp";
cmd.ExecuteNonQuery();
cmd.CommandText = "CREATE TABLE emp (empno INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name VARCHAR(20), last_name VARCHAR(20), birthdate DATE)";
cmd.ExecuteNonQuery();
cmd.CommandText = "CREATE PROCEDURE add_emp(" +
"IN fname VARCHAR(20), IN lname VARCHAR(20), IN bday DATETIME)" +
"BEGIN INSERT INTO emp(first_name, last_name, birthdate) " +
"VALUES(fname, lname, DATE(bday)); END";
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
cn.Close();
Console.WriteLine("Connection closed.");
try
{
Console.WriteLine("Connecting to MySQL...");
cn.Open();
cmd.Connection = cn;
cmd.CommandText = "add_emp;";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("?lname", "Jones");
cmd.Parameters["?lname"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("?fname", "Tom");
cmd.Parameters["?fname"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("?bday", "1940-06-07");
cmd.Parameters["?bday"].Direction = ParameterDirection.Input;
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
cn.Close();
Console.WriteLine("Done.");
}
By this code procedure is created successfully bt when it comes to calling that procedure it throws an error
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 'add_emp' at line 1
|
|
|
|
|
If I were you, I would try to initialize my OdbcCommand object instead of just changing the command text :
OdbcCommand cmd;
string commandText;
try
{
cn.Open();
commandText = "use userdb";
cmd = new OdbcCommand(commandText, cn);
cmd.ExecuteNonQuery();
commandText = "DROP PROCEDURE IF EXISTS add_emp";
cmd = new OdbcCommand(commandText, cn);
cmd.ExecuteNonQuery();
commandText = "CREATE TABLE emp (empno INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name VARCHAR(20), last_name VARCHAR(20), birthdate DATE)";
cmd = new OdbcCommand(commandText, cn);
cmd.ExecuteNonQuery();
commandText = "CREATE PROCEDURE add_emp(" +
"IN fname VARCHAR(20), IN lname VARCHAR(20), IN bday DATETIME) " +
"BEGIN INSERT INTO emp(first_name, last_name, birthdate) " +
"VALUES(fname, lname, DATE(bday)); END";
cmd = new OdbcCommand(commandText, cn);
cmd.ExecuteNonQuery();
}
... and so on in your second try block.
Everytime I tried to reuse a command object to do anything else than its original goal, I ran into troubles.
Initiliaze it with new and see what happens.
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
I have done it this way but nothing happened...same error still exist...
|
|
|
|
|
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.....??
|
|
|
|