Not Me

Not Me

  • NA
  • 15
  • 0

insert statement adding null values

Oct 2 2009 1:01 PM
Here is my code


string sqlInsert = "Insert into status (name) values (@name)";
            string connStr = "DSN=StatusChecker;User Id=user;Password=mypass;";
           
            OdbcConnection odbcCon = new OdbcConnection(connStr);
            try
            {  
                odbcCon.Open();
                OdbcCommand cmdInsert = new OdbcCommand(sqlInsert, odbcCon);
                cmdInsert.Parameters.AddWithValue("@name",textboxUserName.Text);
                cmdInsert.ExecuteNonQuery();
                cmdInsert.Parameters.Clear();
                cmdInsert.Dispose();
                cmdInsert = null;
               

            }
            catch(Exception ex)
            {
                throw new Exception(ex.ToString(), ex);

            }
            finally
            {
                odbcCon.Close();
            }


i am using mysql and if i do a select * form status at the mysql prompt i get


mysql> select * from statu
    -> ;
+----------+------+
| StatusID | name |
+----------+------+
|        1 | NULL|
|        2 | NULL |
|        3 | NULL |
|        4 | NULL |
|        5 | NULL |
|        6 | NULL |
|        7 | NULL |
|        8 | NULL |
|        9 | NULL |
|       10 | NULL |
|       11 | NULL |
|       12 | NULL |
|       13 | NULL |
|       14 | NULL |




I have check to make sure the text box does have text in it.  I don't see where the problem is?

Answers (3)