0

Hi
i'd like to know how to store dynamic string into MySQL database from c#.net desktop application.
I was able to store only fixed data .
Help me pls as i 'm new in database .
thanks

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by smantscheff
0

What is a "dynamic string", what are "fixed data"? Show what you did and what didn't work, then maybe someone will be able to help you.

0

i wanna store some string or test file which might be generated by user at run time.
i need to store it into mysql database.
at present, i can store fixed data something like ( if i put column value as 'test' , then i pass it to DB. mysql can get 'test' as column value. But when i pass variable value (not string) , mysql always get 'NULL' as that column value.

anyway, thanks for your reply. hope to get further help from you fri :)

0

How do you pass the variable value? What does your statement looks like in your code? There is probably an error in your coding so that your variable values do not get into the actual query.
If your mysql server runs a log, you can see in the log file how your query actually gets to the server.

0

How do you pass the variable value? What does your statement looks like in your code? There is probably an error in your coding so that your variable values do not get into the actual query.
If your mysql server runs a log, you can see in the log file how your query actually gets to the server.

here's my code fri,
i use MySQL Command Line Client.
when i use fixed data , it worked fine.

public int id = 3;
public string k = "somevalue";

private void button1_Click(object sender, EventArgs e)
{
     InsertMySQL_GetLast_SP(id,k);
}
public void InsertMySQL_GetLast_SP(int fileid, string value) 
        {
            MySql.Data.MySqlClient.MySqlConnection oConn =
                new MySql.Data.MySqlClient.MySqlConnection("Database=Test;Data Source=localhost;User id=root;Password=12345");
            oConn.Open();


            MySql.Data.MySqlClient.MySqlCommand command =
                new MySql.Data.MySqlClient.MySqlCommand("Test_Insert", oConn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("?p_in_FileID", MySql.Data.MySqlClient.MySqlDbType.Int32));
            command.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("?p_in_Value", MySql.Data.MySqlClient.MySqlDbType.VarChar, 20));
            command.Parameters[0].Value=3;      // worked fine
            command.Parameters[1].Value='value';// worked fine
            command.Parameters[0].Value = fileid;// here, only get 'NULL'
            command.Parameters[1].Value = keyvalue;// here, only get 'NULL'
            command.ExecuteNonQuery(); 

            //long lNewId = (long)command.ExecuteScalar();
            //int lNewId = (int)command.ExecuteScalar();
            oConn.Close();
            //return lNewId;

        }
0

I don't know C#. But I cannot see how "keyvalue" could have a value other than NULL. Nowwhere it gets assigned.
And how do your test the success of your insert query? Maybe you have a problem with the table definition. Would it accept NULL for FileID or for Value?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.