@Saksham我写了3种方法:一种用于插入图像和声音,另一种用于调用这两种方法。
[System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Insert, false)] public bool InsertImage(int ServiceRequestID, string Filename, byte[] image) { try { int i = Adapter.InsertImageIntoServiceRequest(ServiceRequestID, Filename, image); 如果 (i > 0) 返回真;返回假;} 捕捉 { 返回错误;} }
和
[System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Insert, false)] public bool InsertSound(int ServiceRequestID, string Filename, byte[] sound) { try { string file = Filename.Replace(' ', '_') ; int i = Adapter.InsertImageIntoServiceRequest(ServiceRequestID, 文件, 声音); 如果 (i > 0) 返回真;返回假;} 捕捉 { 返回错误;} }
这两个方法在这里被调用:
[System.ComponentModel.DataObjectMethodAttribute (System.ComponentModel.DataObjectMethodType.Insert, true)] public int CreateServiceRequest(string Username,string EMail,string CenterIPIN,int ServiceType,int ServiceStatus,string Notes, DataTable image, DataTable sound) { int rowsAffected; 尝试 { rowsAffected =(int)Adapter.CreateServiceRequest(用户名、电子邮件、CenterIPIN、ServiceType、ServiceStatus、Notes);
ServiceRequestBLL srb = new ServiceRequestBLL();
if (image != null)
{
foreach (DataRow dr in image.Rows)
{
srb.InsertImage(rowsAffected, dr["Filename"].ToString(), (byte[])dr["Image"]);
}
}
if (sound != null)
{
foreach (DataRow dr1 in sound.Rows)
{
try
{
srb.InsertSound(rowsAffected, dr1["Filename"].ToString(), (byte[])dr1["Sound"]);
}
catch (Exception ex)
{
rowsAffected = 0;
}
}
}
}
catch
{
rowsAffected = 0;
}
返回 rowsAffected = 1;
}