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

Recommended Answers

All 5 Replies

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.

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 :)

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.

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;

        }

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.