سلام برنامه من هنگام درج عکس این خطا رو میده . کیس میدونه باید چیکار کنم؟
Path cannot be null.
Parameter name: path
سلام برنامه من هنگام درج عکس این خطا رو میده . کیس میدونه باید چیکار کنم؟
Path cannot be null.
Parameter name: path
احتمالا شما یه آدرس باید میدادین تو کدتون که ندادین
چون اینجا گفته آدرس نمیتونه خالی باشه
شما کدتو بزار تا ببینیم مشکلش کجاس
if (pictureBox1.Image != null)
{
try
{
string strConnection = @"Data Source=SFIX-PC;Initial Catalog=GiahanDarooei;Integrated Security=True";
SqlConnection con1 = newSqlConnection(strConnection);
SqlCommand com1 = newSqlCommand(" INSERT INTO image (GiahName,ImageFile,ImageSize,ImageType) VALUES (@GiahName,@ImageFile,@ImageSize,@ImageType) ", con1);
MemoryStream ms = newMemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
byte[] arrPic = ms.GetBuffer();
ms.Close();
com1.Connection = con1;
con1.Open();
com1.Parameters.Add("@GiahName", SqlDbType.NVarChar, 50).Value = txt1.Text;
com1.Parameters.Add("@ImageFile", SqlDbType.NVarChar, 50).Value = txt2.Text;
com1.Parameters.Add("@ImageSize", SqlDbType.NVarChar, 200).Value = txt3.Text;
byte[] photo = GetPhoto(photoFilePath);
com1.Parameters.Add("@ImageType", SqlDbType.Image, photo.Length).Value = pictureBox1.Image;
com1.ExecuteNonQuery();
con1.Close();
MessageBox.Show("Image saved into database", this.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, this.Text);
}
finally
{
}
}
else
{
MessageBox.Show("Please select an image and try again");
}
آخرین ویرایش به وسیله gwbasic : شنبه 24 فروردین 1392 در 07:06 صبح دلیل: لطفا کد خود را جهت خوانایی در تگ #C قرار دهید
نه همچین فیلدی ندارم
یه جایی از کدتون arrPic را برای ذخیره در دیتابیس ست کردین و دوباره چند خط پایینتر GetPhoto رو به همین منظور صدا کردین. دقیقا مشخص نکردین که این خطا در چه خطی اتفاق می افته احتمال می دم که خطا در GetPhoto اتفاق می افته. این خط رو حذف کنید و از arrPic استفاده کنید
if (pictureBox1.Image != null)
{
try
{
string strConnection = @"Data Source=SFIX-PC;Initial Catalog=GiahanDarooei;Integrated Security=True";
SqlConnection con1 = newSqlConnection(strConnection);
SqlCommand com1 = newSqlCommand(" INSERT INTO image (GiahName,ImageFile,ImageSize,ImageType) VALUES (@GiahName,@ImageFile,@ImageSize,@ImageType) ", con1);
MemoryStream ms = newMemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
byte[] arrPic = ms.GetBuffer();
ms.Close();
com1.Connection = con1;
con1.Open();
com1.Parameters.Add("@GiahName", SqlDbType.NVarChar, 50).Value = txt1.Text;
com1.Parameters.Add("@ImageFile", SqlDbType.NVarChar, 50).Value = txt2.Text;
com1.Parameters.Add("@ImageSize", SqlDbType.NVarChar, 200).Value = txt3.Text;
//byte[] photo = GetPhoto(photoFilePath);
com1.Parameters.Add("@ImageType", SqlDbType.Image, arrPic.Length).Value = arrPic;
com1.ExecuteNonQuery();
con1.Close();
MessageBox.Show("Image saved into database", this.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, this.Text);
}
finally
{
}
}
else
{
MessageBox.Show("Please select an image and try again");
}
ممنون ولی حل نشد اون خطا دوباره تکرارمیشه
لطفا بفرمایی کدوم خط این خطا رو میده و متن خطا رو بطور کامل بگذارید
publicstring photoFilePath;
publicstaticbyte[] GetPhoto(string filePath)
{
FileStream stream = newFileStream(
filePath, FileMode.Open, FileAccess.Read);
BinaryReader reader = newBinaryReader(stream);
byte[] photo = reader.ReadBytes((int)stream.Length);
reader.Close();
stream.Close();
return photo;
دوست عزیز توی کدی که دادین همچین خطی وجود نداره. احتمالا این کد مربوط به متد GetPhoto هست که گفتم کامنت کنید!!!