i have created a software to upload images?
in my application there's a picture box, and when someone click browse button. the picture will show in the picturebox.
so i'm passing the picturebox directly to sql image.
string connetionString = null;
string name = "";
string pass = "";
connetionString = "Data Source=PD-JANAKAN;Initial Catalog=VisaDb;User ID=Madushan;Password=P@19861030";
using (SqlConnection conn = new SqlConnection(connetionString))
{
conn.Open();
String Usr = ReferClass.Uname;
string selectStmt = "select UserId from VisaUserLog where UserName = @Usr";
using (SqlCommand cmd2 = new SqlCommand(selectStmt, conn))
{
cmd2.Parameters.AddWithValue("@Usr", UserName.Text);
SqlDataReader myReader = cmd2.ExecuteReader();
while (myReader.Read())
{
int UsrId = (int)myReader["UserId"];
ReferClass.UserId = UsrId;
}
myReader.Close();
((IDisposable)myReader).Dispose();
}
string cmdInsert = "insert into Visa_UsrDataBase(User_Id, Visa_Country, Cust_Name, Pass_No, Exp_Date, Collect_Date, Assign_by, Collectd_Prson, Visa_Type, Uplad_Doc, Uplad_Image) value (@Uid,@Vcountry,@Cusname,@PassNo,@ExpDate,@CollectDate,@Assigned,@CollectPerson,@VisaType,@Upladpic,@UpladDoc)";
using (SqlCommand cmd = new SqlCommand(cmdInsert, conn))
{
cmd.Parameters.AddWithValue("@Uid", ReferClass.UserId);
cmd.Parameters.AddWithValue("@Vcountry", VisaCountry.SelectedText);
cmd.Parameters.AddWithValue("@Cusname", CustName.Text);
cmd.Parameters.AddWithValue("@PassNo", PassNo.Text);
cmd.Parameters.AddWithValue("@ExpDate", SqlDbType.Date).Value = expData.Value;
cmd.Parameters.AddWithValue("@CollectDate", SqlDbType.Date).Value = colData.Value;
cmd.Parameters.AddWithValue("@Assigned", AssignedPerson.Text);
cmd.Parameters.AddWithValue("@CollectPerson", ColPerson.Text);
cmd.Parameters.AddWithValue("@VisaType", VisaPerson.Text);
cmd.Parameters.AddWithValue("@Upladpic", System.Data.SqlDbType.Image).Value = this.pictureBox1;
cmd.ExecuteNonQuery();
MessageBox.Show("Success");
}
conn.Close();
it gives me an error saying.
No mapping exists from object type System.Windows.Forms.PictureBox to a known managed provider native type.
i put path as well.
that gives me an error saying Incorrect syntax near 'value'.
and i did like this way as well.
byte[] Picture;
Picture = File.ReadAllBytes(ReferClass.PicturePath);
conn.Open();
string cmdInsert = "insert into Visa_UsrDataBase(User_Id, Visa_Country, Cust_Name, Pass_No, Exp_Date, Collect_Date, Assign_by, Collectd_Prson, Visa_Type, Uplad_Doc, Uplad_Image) value (@Uid,@Vcountry,@Cusname,@PassNo,@ExpDate,@CollectDate,@Assigned,@CollectPerson,@VisaType,@Upladpic,@UpladDoc)";
using (SqlCommand cmd = new SqlCommand(cmdInsert, conn))
{
cmd.Parameters.AddWithValue("@Uid", ReferClass.UserId);
cmd.Parameters.AddWithValue("@Vcountry", VisaCountry.SelectedText);
cmd.Parameters.AddWithValue("@Cusname", CustName.Text);
cmd.Parameters.AddWithValue("@PassNo", PassNo.Text);
cmd.Parameters.AddWithValue("@ExpDate", SqlDbType.Date).Value = expData.Value;
cmd.Parameters.AddWithValue("@CollectDate", SqlDbType.Date).Value = colData.Value;
cmd.Parameters.AddWithValue("@Assigned", AssignedPerson.Text);
cmd.Parameters.AddWithValue("@CollectPerson", ColPerson.Text);
cmd.Parameters.AddWithValue("@VisaType", VisaPerson.Text);
cmd.Parameters.AddWithValue("@Upladpic", System.Data.SqlDbType.Image).Value = Picture;
cmd.ExecuteNonQuery();
MessageBox.Show("Success");
}
conn.Close();
it gives me an error saying,
Incorrect syntax near 'value'.
please help me to solve this.