Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello
Plz Please help me with this.
C#
protected void Button1_Click(object sender, EventArgs e)
{
con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString );
            
           
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = txtName.Text.Trim();
cmd.Parameters.Add("@Description", SqlDbType.VarChar).Value = txtDesc.Text.Trim();
cmd.Parameters.Add("@Image", SqlDbType.Image).Value =txtImage.Text.Trim();
cmd.Parameters.Add("@Active", SqlDbType.VarChar).Value = txtActive.Text.Trim();
cmd.Parameters.Add("@CreatedBy", SqlDbType.VarChar).Value = txtCreatedBy.Text.Trim();
cmd.Parameters.Add("@CreatedDate", SqlDbType.DateTime).Value = txtCreDate.Text.Trim();

cmd.Connection = con;
cmd.CommandText = "sp_SqlImage";

//cmd=new SqlCommand ("sp_SqlImage", con);
           con.Open();
            //cmd.CommandType =CommandType.StoredProcedure;
            cmd.ExecuteReader();

            
            //cmd.ExecuteNonQuery();
            con.Close();
}    

I get this error plz please help
Invalid cast from 'System.String' to 'System.Byte[]'. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidCastException: Invalid cast from 'System.String' to 'System.Byte[]'.

Source Error: 


Line 78:             con.Open();
Line 79:             cmd.CommandType =CommandType.StoredProcedure;
Line 80:             cmd.ExecuteReader();
Line 81: 
Line 82:
Posted
Updated 18-Jun-12 1:18am
v2
Comments
Prasad_Kulkarni 18-Jun-12 7:20am    
You've already ask'd this question: Invalid cast from System.String to System.Byte[][^]
Don't re-post your questions, If you want to modify or update your question then use 'Improve question' widget. But don't re-post it.
Nikil0012 18-Jun-12 7:55am    
Sir can you please provide me the solution for this line.Please

you have error in this line

C#
cmd.Parameters.Add("@Image", SqlDbType.Image).Value =txtImage.Text.Trim();


in this you cannot save text value.
you store here byte array for this datatype.
 
Share this answer
 
v2
Check out the image field name in database(its datatype of image which stores the data in byte format) and you are passing the data in string format...thats why its giving you the error..

for checking make your image field to null or remove the

cmd.Parameters.Add("@Image", SqlDbType.Image).Value =txtImage.Text.Trim();


then save your data... you will recognize the error easily..


Thanks
 
Share this answer
 

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