Click here to Skip to main content
16,016,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir i am using webservice to save the images in database

webservice code

C#
public void save_Image(int id, byte []ar)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText="insert into tbimage values(@id,@nam)";
        cmd.Connection=con;
        cmd.Parameters.Add("@id",SqlDbType.Int).Value=id;
        cmd.Parameters.Add("@nam",SqlDbType.Image).Value=ar;
        cmd.ExecuteNonQuery();
        cmd.Dispose();

    }


Webform which consumes this webservice

C#
protected void Button1_Click(object sender, EventArgs e)
    {
        abc.WebService obj = new abc.WebService();
        int ln = FileUpload1.PostedFile.ContentLength;
        byte []arr=new byte[ln];
        FileStream fs = new FileStream(FileUpload1.PostedFile.FileName,FileMode.Open,FileAccess.Read);
        fs.Read(arr, 0, ln - 1);
        fs.Close();
        obj.save_rec(Convert.ToInt32(TextBox1.Text),arr);
        TextBox1.Text = string.Empty;
        TextBox1.Focus();


    }


please help
Posted
Updated 26-Jan-12 19:38pm
v2

 
Share this answer
 
 
Share this answer
 
Comments
singlaNitish 27-Jan-12 7:45am    
though code at ur link is working but i am unable to find error in my code please can u help
Abhi KA 27-Jan-12 7:47am    
what is the error
singlaNitish 27-Jan-12 8:06am    
its a run time error file not found .... though the exists
can u please try it on ur machine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900