i entered values in the textbox.and displayed it using response.write
its displaying fine.still i cant possible to upload to db

On Dec 22, 4:31 pm, "web master" <[email protected]> wrote:
> Hi Are you entering any value into the Textbox ? Because what this massage
> showing that "Column 'Title' cannot be null".
> So Some how your code might not be getting values of the text box.
> If you are trying to upload the file without entering values into the
> textbox , try entering the values in the text box and check weather that
> worked or not ?
>
> Thanks,
> Pratik
>
>
>
> On Mon, Dec 22, 2008 at 4:21 PM, nag <[email protected]> wrote:
>
> > 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();
>
> >    }
> > }- Hide quoted text -
>
> - Show quoted text -

Reply via email to