السلام عليكم ورحمة الله وبركاته:
إخواني أنا مبتدئة في ال SQL Server 2000 و عندي معرفة قليلة في ال #C ، أقوم حاليا بمحاولة لربط ال SQL مع السي شارب لتخزين أو استرجاع الصور المخزنة في ال SQL في حقل من نوع Image. الحمد لله قمت بعملية الربط بشكل صحيح، ولكن المشكلة عند تنفيذ الكود الذي يخزن الصورة في الجدول يظهر ال exception التالي:
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
سأقوم بكتابة الكود لكم، أتمنى أن تساعدوني في معرفة الخطأ، قد يكون الخطأ واضح ولكنني مبتدئة في ال SQLكما ذكرت فارجو أن تعذروني.
private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection con= new SqlConnection("workstation id=MARYOOM;packet size=4096;user id=sa;data source=MARYOOM;persist security info=False;initial catalog=maryam");
SqlCommand cmd= new SqlCommand();
SqlParameter param1=new SqlParameter("@Image",SqlDbType.Image);
byte[] b;
emoryStream ms= new MemoryStream();
pictureBox1.Image.Save(ms,pictureBox1.Image.RawFormat);
b=ms.GetBuffer();
con.Open();
cmd.CommandType= CommandType.StoredProcedure;
cmd.CommandText = "InsertImage";
cmd.Connection=con;
cmd.Parameters.Add(param1);
con.Close();
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
} جزاكم الله خيرا
