hi
i trying to upload file to mysql db with one text field.when i click
on upload button i',m getting following error
ERROR [HYT00] [MySQL][ODBC 3.51 Driver][mysqld-5.0.51a-community-nt]
Column 'Title' cannot be null
 its working fine in local ms sql.

please let me knw wer i'm wrong
here is my code

using System.Data.Odbc;
partial class _Default : System.Web.UI.Page
{
    protected void Upload_Click(object sender, System.EventArgs e)
    {
        FileUpload fileUpload1 = (FileUpload)this.FindControl
("fileUpload1");

        if (fileUpload1.PostedFile == null || string.IsNullOrEmpty
(fileUpload1.PostedFile.FileName) ||
fileUpload1.PostedFile.InputStream == null)
        {
            Label1.Text = "Please Upload Valid picture file";
            return;
        }

        string extension = System.IO.Path.GetExtension
(fileUpload1.PostedFile.FileName).ToLower();

        string titl = TextBox1.Text.Trim();

        string MIMEType = null;
        switch (extension)
        {
            case ".gif":
                MIMEType = "image/gif"; break;
            case ".doc":
            case ".rtf":
                MIMEType = "application/msword"; break;
            case ".zip":
                MIMEType = "x-zip-compressed"; break;
            case ".jpg":
            case ".jpeg":
            case ".jpe":
                MIMEType = "image/jpeg"; break;
            case ".png":
                MIMEType = "image/png"; break;
            default:

                Label1.Text = "Not a Valid file format";
                return;

        }
        String connString = "Driver={MySQL ODBC 3.51
Driver};Server=mysql9.servername.com;Database=xyz;user
id=kv;password=kv";
        OdbcConnection myConnection = new OdbcConnection(connString);
            const string SQL = "INSERT INTO PictureTable
(Title,MIMEType,Image) VALUES (@Title, @MIMEType, @ImageData)";

            OdbcCommand myCommand = new OdbcCommand(SQL,myConnection);
            myCommand.Parameters.Add("@Title", OdbcType.VarChar).Value
= TextBox1.Text.Trim();
            myCommand.Parameters.AddWithValue("@MIMEType",
OdbcType.VarChar).Value = MIMEType;
            byte[] imageBytes = new byte
[fileUpload1.PostedFile.InputStream.Length];
            fileUpload1.PostedFile.InputStream.Read(imageBytes, 0,
imageBytes.Length);
            myCommand.Parameters.AddWithValue("@ImageData",
imageBytes);
            myConnection.Open();
            myCommand.ExecuteNonQuery();
            myConnection.Close();


    }
}

Reply via email to