After spending several hours i am unable to figure out that why null values are being inserted into mySQL table using ASP.NET web page. I am using odbc connector for this.Below is the code for the same.
public int Insert(string FirstName, string LastName, int age)
{
OdbcConnection conn = new OdbcConnection(connStr);
conn.Open();
OdbcCommand odcmd_Insert = new OdbcCommand("INSERT INTO webuse(firstName,lastName,age) VALUES(@param1,@param2,@param3)",conn);
odcmd_Insert.Connection = conn;
odcmd_Insert.CommandType = System.Data.CommandType.Text;
try
{
odcmd_Insert.Parameters.Add(new OdbcParameter( "@param1", FirstName));
odcmd_Insert.Parameters.Add(new OdbcParameter( "@param2", LastName));
odcmd_Insert.Parameters.Add( new OdbcParameter("@param3", age));
return odcmd_Insert.ExecuteNonQuery();
}
catch (OdbcException e)
{
throw;
}
finally {
odcmd_Insert.Dispose();
conn.Close();
conn.Dispose();
}
}
I have debugged the code and all things seems well but all columns are updated with null values. Please help i am a noob to ASP.NET.