Hi everyone,
I've created 1 windows app in that app i've created Registration form including image fields.After filling all the details in that form when i click on save button i'm runtime error(Failed to convert parameter value from a Bitmap to a Byte[])..Can anyone tell me how to resolve this issue..I'm try to resolve this from since last 4days.I posted the question on so many forums but no use atleast i came to bytes forum..I hope I'll get the solution from this forum.
This is the code which I've written under button method:: - private void btnaddinfo_Click(object sender, EventArgs e)
-
{
-
string scn = ConfigurationManager.ConnectionStrings["Myconn"].ConnectionString;
-
using (SqlConnection cn = new SqlConnection(scn))
-
{
-
using (SqlCommand cmd = new SqlCommand("SP_Info", cn))
-
{
-
try
-
{
-
byte[] photo = GetPhoto(imageloc);
-
-
cmd.CommandType = CommandType.StoredProcedure;
-
-
SqlParameter p1 = new SqlParameter("@Hp_Number", SqlDbType.NVarChar, 50);
-
SqlParameter p2 = new SqlParameter("@Customer_Name", SqlDbType.VarChar, 50);
-
SqlParameter p3 = new SqlParameter("@Customer_Contact_Number", SqlDbType.NVarChar, 15);
-
SqlParameter p4 = new SqlParameter("@Guarantor_Name", SqlDbType.VarChar, 50);
-
SqlParameter p5 = new SqlParameter("@Guarantor_Contact_Number", SqlDbType.NVarChar, 15);
-
SqlParameter p6 = new SqlParameter("@Hp_Date", SqlDbType.Date);
-
SqlParameter p7 = new SqlParameter("@Customer_Address", SqlDbType.NVarChar, Max);
-
SqlParameter p8 = new SqlParameter("@Vehicle", SqlDbType.VarChar, 50);
-
SqlParameter p9 = new SqlParameter("@Vehicle_Model", SqlDbType.VarChar, 50);
-
SqlParameter p10 = new SqlParameter("@Vehicle_Number", SqlDbType.NVarChar, 50);
-
SqlParameter p11 = new SqlParameter("@Chasis_Number", SqlDbType.NVarChar, 50);
-
SqlParameter p12 = new SqlParameter("@Engine_Number", SqlDbType.NVarChar, 50);
-
SqlParameter p13 = new SqlParameter("@FC_Date", SqlDbType.Date);
-
SqlParameter p14 = new SqlParameter("@Insurance_Date", SqlDbType.Date);
-
SqlParameter p15 = new SqlParameter("@Insurance_Amount", SqlDbType.Int);
-
SqlParameter p16 = new SqlParameter("@Paid_Amount", SqlDbType.Int);
-
SqlParameter p17 = new SqlParameter("@Vehicle_Pic",SqlDbType.Image,photo.Length);
-
SqlParameter p18 = new SqlParameter("@Customer_Pic ", SqlDbType.Image, photo.Length);
-
SqlParameter p19 = new SqlParameter("@Guarantor_Pic ", SqlDbType.Image, photo.Length);
-
SqlParameter p20 = new SqlParameter("@Documents_Pic", SqlDbType.Image, photo.Length);
-
SqlParameter p21 = new SqlParameter("@Insurance_Pic", SqlDbType.Image, photo.Length);
-
-
cmd.Parameters.Add(p1).Value = tbhpnum.Text;
-
cmd.Parameters.Add(p2).Value = tbcusnam.Text;
-
cmd.Parameters.Add(p3).Value=tbcusmblno.Text;
-
cmd.Parameters.Add(p4).Value = tbguanam.Text;
-
cmd.Parameters.Add(p5).Value = tbguamblno.Text;
-
cmd.Parameters.Add(p6).Value = DateTime.Parse(tbhpdat.Text);
-
cmd.Parameters.Add(p7).Value = tbcusadd.Text;
-
cmd.Parameters.Add(p8).Value = tbveh.SelectedItem.ToString();
-
cmd.Parameters.Add(p9).Value = tbvehmod.SelectedItem.ToString();
-
cmd.Parameters.Add(p10).Value = tbvehnum.Text;
-
cmd.Parameters.Add(p11).Value = tbchanum.Text;
-
cmd.Parameters.Add(p12).Value = tbengnum.Text;
-
cmd.Parameters.Add(p13).Value = DateTime.Parse(tbfcdat.Text);
-
cmd.Parameters.Add(p14).Value = DateTime.Parse(tbinsdat.Text);
-
cmd.Parameters.Add(p15).Value = Convert.ToInt32(tbinsamt.Text);
-
cmd.Parameters.Add(p16).Value = Convert.ToInt32(tbpaiamt.Text);
-
cmd.Parameters.Add(p17).Value = boxvehpic;
-
cmd.Parameters.Add(p18).Value = boxcuspic;
-
cmd.Parameters.Add(p19).Value = boxguapic;
-
cmd.Parameters.Add(p20).Value=boxdocpic;
-
cmd.Parameters.Add(p21).Value = boxinspic;
-
-
if (cn.State != ConnectionState.Open)
-
cn.Open();
-
int count = cmd.ExecuteNonQuery();
-
if (count == 1)
-
{
-
MessageBox.Show(count.ToString() + "Record(s) Saved.");
-
}
-
else
-
{
-
MessageBox.Show("Please correct the error which you have entered and then click on addinformation button");
-
}
-
}
-
catch (SqlException ex)
-
{
-
MessageBox.Show(ex.ToString());
-
-
}
-
finally
-
{
-
if (cn.State == ConnectionState.Open)
-
cn.Close();
-
}
-
}
-
}
-
}
-
-
-
External Byte[] method code:: -
public static byte[] GetPhoto(string imageloc)
-
{
-
byte[] photo= null;
-
FileStream stream = new FileStream(imageloc, FileMode.Open, FileAccess.Read);
-
BinaryReader reader = new BinaryReader(stream);
-
photo= reader.ReadBytes((int)stream.Length);
-
-
reader.Close();
-
stream.Close();
-
-
return photo;
-
}
-
-
Stored Procedure:: -
create PROC SP_Info
-
(
-
@Hp_Number nvarchar(50),
-
@Customer_Name varchar(50),
-
@Customer_Contact_Number nvarchar(15),
-
@Guarantor_Name varchar(50),
-
@Guarantor_Contact_Number nvarchar(15),
-
@Hp_Date date,
-
@Customer_Address nvarchar(MAX),
-
@Vehicle varchar(50),
-
@Vehicle_Model varchar(50),
-
@Vehicle_Number nvarchar(50),
-
@Chasis_Number nvarchar(50),
-
@Engine_Number nvarchar(50),
-
@FC_Date date,
-
@Insurance_Date date,
-
@Insurance_Amount int,
-
@Paid_Amount int,
-
@Vehicle_Pic image,
-
@Customer_Pic image,
-
@Guarantor_Pic image,
-
@Documents_Pic image,
-
@Insurance_Pic image
-
)
-
AS
-
BEGIN
-
Insert into Info values(@Hp_Number,
-
@Customer_Name,
-
@Customer_Contact_Number,
-
@Guarantor_Name,
-
@Guarantor_Contact_Number,
-
@Hp_Date,
-
@Customer_Address,
-
@Vehicle,
-
@Vehicle_Model,
-
@Vehicle_Number,
-
@Chasis_Number,
-
@Engine_Number,
-
@FC_Date,
-
@Insurance_Date,
-
@Insurance_Amount,
-
@Paid_Amount,
-
@Vehicle_Pic,
-
@Customer_Pic,
-
@Guarantor_Pic,
-
@Documents_Pic,
-
@Insurance_Pic)
-
END
6 3432
Lines 52-56: -
cmd.Parameters.Add(p17).Value = boxvehpic;
-
cmd.Parameters.Add(p18).Value = boxcuspic;
-
cmd.Parameters.Add(p19).Value = boxguapic;
-
cmd.Parameters.Add(p20).Value=boxdocpic;
-
cmd.Parameters.Add(p21).Value = boxinspic;
What are boxcuspic , boxguapic , boxdocpic and boxinspic ?
In Registration form I used 5 picture boxes and for my understanding purpose I gave the names for that picture boxes..
1.boxvehpic = vehicle picture box
2.boxcuspic = customer picture box
3.boxguapic= guarantor picture box
4.boxdocpic= Document picture box
5.boxinspic= Insurance doc picture box
I changed my code like this,Eventhough no use still same error is persisting..... - private void btnaddinfo_Click(object sender, EventArgs e)
-
{
-
string scn = ConfigurationManager.ConnectionStrings["Myconn"].ConnectionString;
-
using (SqlConnection cn = new SqlConnection(scn))
-
{
-
using (SqlCommand cmd = new SqlCommand("SP_Info", cn))
-
{
-
try
-
{
-
byte[] img = null;
-
FileStream fs = new FileStream(imageloc, FileMode.Open, FileAccess.Read);
-
BinaryReader br = new BinaryReader(fs);
-
img = br.ReadBytes((int)fs.Length);
-
-
cmd.CommandType = CommandType.StoredProcedure;
-
-
cmd.Parameters.Add("@Hp_Number", SqlDbType.NVarChar, 50).Value = tbhpnum.Text; ;
-
cmd.Parameters.Add("@Customer_Name", SqlDbType.VarChar, 50).Value = tbcusnam.Text;
-
cmd.Parameters.Add("@Customer_Contact_Number", SqlDbType.NVarChar, 15).Value = tbcusmblno.Text;
-
cmd.Parameters.Add("@Guarantor_Name", SqlDbType.VarChar, 50).Value = tbguanam.Text;
-
cmd.Parameters.Add("@Guarantor_Contact_Number", SqlDbType.NVarChar, 15).Value = tbguamblno.Text;
-
cmd.Parameters.Add("@Hp_Date", SqlDbType.DateTime).Value = DateTime.Parse(tbhpdat.Text);
-
cmd.Parameters.Add("@Customer_Address", SqlDbType.NVarChar, Max).Value = tbcusadd.Text;
-
cmd.Parameters.Add("@Vehicle", SqlDbType.VarChar, 50).Value = tbveh.SelectedItem.ToString();
-
cmd.Parameters.Add("@Vehicle_Model", SqlDbType.VarChar, 50).Value = tbvehmod.SelectedItem.ToString();
-
cmd.Parameters.Add("@Vehicle_Number", SqlDbType.NVarChar, 50).Value = tbvehnum.Text;
-
cmd.Parameters.Add("@Chasis_Number", SqlDbType.NVarChar, 50).Value = tbchanum.Text;
-
cmd.Parameters.Add("@Engine_Number", SqlDbType.NVarChar, 50).Value = tbengnum.Text;
-
cmd.Parameters.Add("@FC_Date", SqlDbType.DateTime).Value = DateTime.Parse(tbfcdat.Text);
-
cmd.Parameters.Add("@Insurance_Date", SqlDbType.DateTime).Value = DateTime.Parse(tbinsdat.Text);
-
cmd.Parameters.Add("@Insurance_Amount", SqlDbType.Int).Value = Convert.ToInt32(tbinsamt.Text);
-
cmd.Parameters.Add("@Paid_Amount", SqlDbType.Int).Value = Convert.ToInt32(tbpaiamt.Text);
-
cmd.Parameters.Add("@Vehicle_Pic", SqlDbType.Image).Value = boxvehpic;
-
cmd.Parameters.Add("@Customer_Pic", SqlDbType.Image).Value = boxcuspic;
-
cmd.Parameters.Add("@Guarantor_Pic", SqlDbType.Image).Value = boxguapic;
-
cmd.Parameters.Add("@Documents_Pic", SqlDbType.Image).Value = boxdocpic;
-
cmd.Parameters.Add("@Insurance_Pic", SqlDbType.Image).Value = boxinspic;
-
-
if (cn.State != ConnectionState.Open)
-
cn.Open();
-
int count = cmd.ExecuteNonQuery();
-
if (count == 1)
-
{
-
MessageBox.Show(count.ToString() + "Record(s) Saved.");
-
}
-
else
-
{
-
MessageBox.Show("Please correct the error which you have entered and then click on addinformation button");
-
}
-
}
-
catch (SqlException ex)
-
{
-
MessageBox.Show(ex.ToString());
-
-
}
-
finally
-
{
-
if (cn.State == ConnectionState.Open)
-
cn.Close();
-
}
-
}
-
}
-
}
A picture box control is not a byte array.
You need to retrieve the picture from the picture box control and convert it into a byte array before you attempt to update the database with a byte array.
This is why you are getting the error message: Failed to convert parameter value from a Bitmap to a Byte[]
-Frinny
I resolved my error of my self...
Could you please share what you did to resolve the problem so that other people facing the same problem can find a solution?
Thanks
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Igor Okulist |
last post by:
int func(void**);
{
short* p = NULL;
func(&p); //<<< here
}
Could somebody remind me why is this not allowed ?
error message: "cannot convert parameter from 'short **' to 'void **'"
|
by: Chris Crowe [MVP 1997 -> 2006] |
last post by:
I am having major problems using GetStoredProcCommand and using Parameters
in the same function call in the latest builds of the Enterprise Library
Data.
The error I get is :
Failed to...
|
by: kaizen |
last post by:
Hi,
i wrote the code in C and compiled in VC++ compiler. at that time it
has thrown the below mentioned error.
error C2664: 'strcpy' : cannot convert parameter 2 from 'char' to
'const char *'...
|
by: mikejacobz |
last post by:
Hi, I am using the Enterprise Application Blocks (Data Access
Application Block 2005) and all I want to do is pass in a date as a
parameter to a Stored procedure.
e.g
private void...
|
by: weird0 |
last post by:
Here is the code for executing stored procedure ExecuteSP() , and object that sets all its parameters in other
functions and the stored procedure. I think it has something to do
with db datatypes...
|
by: sweatha |
last post by:
Hi
In sql server 2005 I have a column as
GraduationYear Decimal(4,0). In asp.net I used the coding for that as
SqlParameter GraduationYear = new SqlParameter("@GraduationYear",...
|
by: balajius |
last post by:
I am using VS2008 with asp.net 3.5 and enterprise library 4.1. I am getting the following error when I try to connect to database.
"Failed to convert parameter value from a SqlParameter to a String"...
|
by: androm |
last post by:
when i run my code i get this error message
"Failed to convert parameter value from a SqlParameter to a DateTime."
& i couldn't find what is wrong..... here's my code
protected void...
|
by: dougancil |
last post by:
I'm trying to pass values in a SessionState from one page to another and then post them to a SQL database. When I click on the submit button on my submit page, I get this error:
Failed to...
|
by: Mickle |
last post by:
here is my code, I was trying to convert arraybyte to bitmap after placing some value in array and convert it back to bitmap, actually i'm working with bilinear interpolation. i really appreciate...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |