When i am executing the code i am getting a System.IndexOutOfRangeException - c#

when i am executing the code i am getting the exception in frmtime is
System.IndexOutOfRangeException: Index was outside the bounds of the
array
public IList<ExamSeatAllotmentEntity> GetAttendence1(string frmtime, string totime, DateTime date, int RoomNo)
{
List<ExamSeatAllotmentEntity> ObjTestList = new List<ExamSeatAllotmentEntity>();
//List<QuestionTypeEntity> ObjQTList = new List<QuestionTypeEntity>();
SqlParameter[] Parms = new SqlParameter[1];
Parms[0] = new SqlParameter("#RoomNo", SqlDbType.Int);
Parms[0].Value = RoomNo;
Parms[1] = new SqlParameter("#FromTime", SqlDbType.Time);
Parms[1].Value = frmtime;
Parms[2] = new SqlParameter("#Totime", SqlDbType.Time);
Parms[2].Value = totime;
Parms[3] = new SqlParameter("#Date", SqlDbType.DateTime);
Parms[3].Value = date;
DataSet dsTest = SqlHelper.ExecuteDataset(SqlHelper.connString, CommandType.StoredProcedure, SQL_PROC_GET_Attendence1, Parms);
if (dsTest != null && dsTest.Tables.Count == 1)
{
ObjTestList = (from test in dsTest.Tables[0].AsEnumerable()
select new ExamSeatAllotmentEntity()
{
// CourseID = test.Field<int>("CourseID"),
StudentId = test.Field<int>("StudentId"),
Fname = test.Field<string>("Fname"),
SeatNo = test.Field<string>("SeatNo"),
Attendence = test.Field<string>("Attendence")
}).ToList<ExamSeatAllotmentEntity>();
}
return ObjTestList;
}

new SqlParameter[1]
You just made an array that can only hold one item.

This would be the problem:
SqlParameter[] Parms = new SqlParameter[1];
You are specifying a length of 1 element: Parms[0]
Correct the size of the array to allow 4 elements:
SqlParameter[] Parms = new SqlParameter[4];
In case you want to add more parameters, you might want to create a list and then transform via ToArray().

Change
SqlParameter[] Parms = new SqlParameter[1];
to
SqlParameter[] Parms = new SqlParameter[4];

Related

why i got the error "Input string was not in a correct format"

I am inserting data from datagridview into database , I debug my code and found the error Input string was not in a correct format. in the following line
Convert.ToInt32(dgvResult.Rows[i].Cells[9].Value.ToString())
this column is an integer column and when i replaced this line with integer value for example number 3 insert completed without errors , and the other integer columns also inserted same way without any error
this is my code :
if (checkApproveResult.Checked == false && chkupdateApproved.Checked == false)
{
for (int i = 0; i < dgvResult.Rows.Count; i++)
{
result.UPDATE_LAB_RESULTS(Convert.ToInt32(txtOrder.Text),
dgvResult.Rows[i].Cells[7].Value.ToString(),
5,
dgvResult.Rows[i].Cells[6].Value.ToString(),
txtExamUser.Text,
DateTime.Parse(DateTimeExamined.Value.ToString()),
Convert.ToInt32(dgvResult.Rows[i].Cells[2].Value),
dgvResult.Rows[i].Cells[4].Value.ToString(),
dgvResult.Rows[i].Cells[5].Value.ToString(),
Convert.ToInt32(dgvResult.Rows[i].Cells[9].Value.ToString()),
Convert.ToInt32(txtPno.Text),
Convert.ToInt32(txtcustid.Text),
txtReqForm.Text,
dgvResult.Rows[i].Cells[1].Value.ToString(),
Convert.ToInt32(dgvResult.Rows[i].Cells[8].Value.ToString()));
}
MessageBox.Show("Result Saved Successfully ", "Entering Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (chkupdateApproved.Checked == true)
{
for (int i = 0; i < dgvResult.Rows.Count; i++)
{
result.ADD_LAB_RESULTS_UPDATES(Convert.ToInt32(txtsampleid.Text),
Convert.ToInt32(txtOrder.Text),
Convert.ToInt32(dgvResult.Rows[i].Cells[2].Value),
Convert.ToInt32(txtgroupid.Text),
"YES",
6,
dgvResult.Rows[i].Cells[11].Value.ToString(),
DateTime.Parse(DateTimeExamined.Value.ToString()),
dgvResult.Rows[i].Cells[13].Value.ToString(),
DateTime.Parse(dateTimeApprove.Value.ToString()),
dgvResult.Rows[i].Cells[4].Value.ToString(),
dgvResult.Rows[i].Cells[5].Value.ToString(),
dgvResult.Rows[i].Cells[6].Value.ToString(),
Convert.ToInt32(txtpackageid.Text),
Convert.ToInt32(dgvResult.Rows[i].Cells[9].Value.ToString()),
2,
Convert.ToInt32(txtPno.Text),
Convert.ToInt32(txtcustid.Text), txtReqForm.Text,
Convert.ToInt32(dgvResult.Rows[i].Cells[8].Value.ToString()),
txtupdatedby.Text,
DateTime.Parse(dateupdate.Value.ToString()));
}
update.UPDATE_LAB_RESULT_STATUS(Convert.ToInt32(txtOrder.Text), Convert.ToInt32(txtsampleid.Text), 2);
MessageBox.Show("Result Updated Successfully ", "Update Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
And the code for ADD_LAB_RESULT_UPDATES was :
public void ADD_LAB_RESULTS_UPDATES(int SAMPLE_ID, int ORDER_ID,int TESTID,int GROUPID, string NORMAL_RESULT,
int SAMPLE_STATUS,string EXAMINED_BY,DateTime EXAMINED_DATE, string APPROVED_BY, DateTime APPROVED_DATE,
string RESULT_NUMBER, string RESULT_REPORT, string RESULT_NOTE,int packageid, int machine_id, int deptid,
int patient_no, int custid, string REQ_FORM_NO,int serial,string UPDATED_BY,DateTime UPDATED_DATE)
{
DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
DAL.open();
SqlParameter[] param = new SqlParameter[22];
param[0] = new SqlParameter("#SAMPLE_ID", SqlDbType.Int);
param[0].Value = SAMPLE_ID;
param[1] = new SqlParameter("#ORDER_ID", SqlDbType.Int);
param[1].Value = ORDER_ID;
param[2] = new SqlParameter("#TESTID", SqlDbType.Int);
param[2].Value = TESTID;
param[3] = new SqlParameter("#GROUPID", SqlDbType.Int);
param[3].Value = GROUPID;
param[4] = new SqlParameter("#NORMAL_RESULT", SqlDbType.VarChar, 10);
param[4].Value = NORMAL_RESULT;
param[5] = new SqlParameter("#SAMPLE_STATUS", SqlDbType.Int);
param[5].Value = SAMPLE_STATUS;
param[6] = new SqlParameter("#EXAMINED_BY", SqlDbType.VarChar, 50);
param[6].Value = EXAMINED_BY;
param[7] = new SqlParameter("#EXAMINED_DATE", SqlDbType.DateTime);
param[7].Value = EXAMINED_DATE;
param[8] = new SqlParameter("#APPROVED_BY", SqlDbType.VarChar, 50);
param[8].Value = APPROVED_BY;
param[9] = new SqlParameter("#APPROVED_DATE", SqlDbType.DateTime);
param[9].Value = APPROVED_DATE;
param[10] = new SqlParameter("#RESULT_NUMBER", SqlDbType.VarChar, 50);
param[10].Value = RESULT_NUMBER;
param[11] = new SqlParameter("#RESULT_REPORT", SqlDbType.VarChar, 2000);
param[11].Value = RESULT_REPORT;
param[12] = new SqlParameter("#RESULT_NOTE", SqlDbType.VarChar, 200);
param[12].Value = RESULT_NOTE;
param[13] = new SqlParameter("#packageid", SqlDbType.Int);
param[13].Value = packageid;
param[14] = new SqlParameter("#machine_id", SqlDbType.Int);
param[14].Value = machine_id;
param[15] = new SqlParameter("#deptid", SqlDbType.Int);
param[15].Value = deptid;
param[16] = new SqlParameter("#patient_no", SqlDbType.Int);
param[16].Value = patient_no;
param[17] = new SqlParameter("#custid", SqlDbType.Int);
param[17].Value = custid;
param[18] = new SqlParameter("#REQ_FORM_NO", SqlDbType.VarChar, 50);
param[18].Value = REQ_FORM_NO;
param[19] = new SqlParameter("#serial", SqlDbType.Int);
param[19].Value = serial;
param[20] = new SqlParameter("#UPDATED_BY", SqlDbType.VarChar, 50);
param[20].Value = UPDATED_BY;
param[21] = new SqlParameter("#UPDATED_DATE", SqlDbType.DateTime);
param[21].Value = UPDATED_DATE;
DAL.ExecuteCommand("ADD_LAB_RESULTS_UPDATES", param);
DAL.close();
}
the error with parameter 14 machine_id
also the table in the database machine_id int.
What is the error ?
More information I have first if statement (update statement)
result. UPDATE_LAB_RESULTS includes same parameter machine_id and its working and inserting without errors.
Second if statement (insert statement) and show the error with machine_id parameter.
You have to check the following :
1- check the parameter list variables types (string , int , ...) and compare it with your procedure you will find one variable type different in the stored procedure integer and in the parameter list string.

Oracle SQL with parameters not working?

I'm familiar with SQL Server but new to Oracle. I'm working on doing a bulk insert or update using the Array technique I've found in some examples. However, I must be doing this incorrect because I'm getting errors about "invalid table.column". I have a feeling it has to do with the way I'm trying to assign parameter names in the in-line SQL and command parameters. In the example I've seen they use numeric values for the parameters like ":1, :2, :3" but if possible I would like to use ":paramtername1, :parametername2, :parametername3".
Here is what I'm doing
sbQuery.Append("update SAP_EMPLOYEE set ");
sbQuery.Append(" EMP_ID = :p_EmployeeId, EVENT_FROM_DT = :p_EventFromDate, EVENT_TYP = :p_EventType, EVENT_RSN = :p_EventRsn,");
sbQuery.Append(" where Emp = :p_Employee");
Then I create arrays to add the values to
string[] arrEmployee = new string[listEmployee.Count];
string[] arrEmployeeId = new string[listEmployee.Count];
DateTime[] arrEventFromDt = new DateTime[listEmployee.Count];
string[] arrEventTyp = new string[listEmployee.Count];
string[] arrEventRsn = new string[listEmployee.Count];
Populate the arrays
int i = 0;
foreach (SAP_EMPLOYEE item in listEmployee)
{
arrEmployee[i] = item.EMP;
arrEmployeeId[i] = item.EMP_ID;
if(item.EVENT_FROM_DT.HasValue)
{
arrEventFromDt[i] = item.EVENT_FROM_DT.Value;
}
arrEventTyp[i] = item.EVENT_TYP;
arrEventRsn[i] = item.EVENT_RSN;
i++;
}
Then call the connection, cmd, query
OracleConnection objConnection = new OracleConnection(connString);
using (objConnection)
{
objConnection.Open();
//create Oracle parameters and pass arrays of data
OracleParameter p_Employee = new OracleParameter();
p_Employee.OracleDbType = OracleDbType.Varchar2;
p_Employee.Value = arrEmployee;
OracleParameter p_EmployeeId = new OracleParameter();
p_EmployeeId.OracleDbType = OracleDbType.Varchar2;
p_EmployeeId.Value = arrEmployeeId;
OracleParameter p_EventFromDate = new OracleParameter();
p_EventFromDate.OracleDbType = OracleDbType.Date;
p_EventFromDate.Value = arrEventFromDt;
OracleParameter p_EventType = new OracleParameter();
p_EventType.OracleDbType = OracleDbType.Char;
p_EventType.Value = arrEventTyp;
OracleParameter p_EventRsn = new OracleParameter();
p_EventType.OracleDbType = OracleDbType.Char;
p_EventType.Value = arrEventRsn;
OracleCommand objCmd = objConnection.CreateCommand();
objCmd.CommandText = sbQuery.ToString();
objCmd.ArrayBindCount = arrEmployee.Length;
objCmd.Parameters.Add(p_Employee);
objCmd.Parameters.Add(p_EmployeeId);
objCmd.Parameters.Add(p_EventFromDate);
objCmd.Parameters.Add(p_EventType);
objCmd.Parameters.Add(p_EventRsn);
objCmd.ExecuteNonQuery();
}

Repeated values in list in while(reader.Read()) {}

[WebMethod]
public List<reports> getMyReports( int user_id )
{
string cs = ConfigurationManager.ConnectionStrings["ReportDB"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("getAllReportsByUserID", con);
cmd.CommandType = CommandType.StoredProcedure;
List<reports> repers = new List<reports>();
//users[][] liser = new users[][];
SqlParameter user_id_parameter = new SqlParameter("#user_id", user_id);
cmd.Parameters.Add(user_id_parameter);
reports report = new reports();
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
report.id = Convert.ToInt32(reader["id"]);
report.title = reader["title"].ToString();
report.description = reader["description"].ToString();
report.anonymous = (bool)reader["anonymous"];
report.location = reader["location"].ToString();
report.status = reader["status"].ToString();
report.category = reader["category"].ToString();
report.date = (DateTime)reader["date"];
report.picture_url = reader["picture_url"].ToString();
report.admin_id = Convert.ToInt32(reader["admin_id"]);
repers.Add(report);
}
return repers;
}
}
I have the top function that calls the following stored procedure:
CREATE Proc [dbo].[getAllReportsByUserID]
#user_id int
as
Begin
Select
id,
title,
description,
anonymous,
location,
status,
category,
date,
picture_url,
admin_id
from reports
where user_id = #user_id
End
I have tested the procedure individually and it works fine. Yet, when I test the WebService created above I get a list with the last value duplicated along the whole list.
Can someone please help me figure out why do I get the same (last)value repeated over and over again?
By creating the report object before the loop and reusing it repeatedly, you insert a reference to that same object multiple times in your list.
You should create the report object inside your loop:
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
reports report = new reports();
report.id = Convert.ToInt32(reader["id"]);
report.title = reader["title"].ToString();
report.description = reader["description"].ToString();
report.anonymous = (bool)reader["anonymous"];
report.location = reader["location"].ToString();
report.status = reader["status"].ToString();
report.category = reader["category"].ToString();
report.date = (DateTime)reader["date"];
report.picture_url = reader["picture_url"].ToString();
report.admin_id = Convert.ToInt32(reader["admin_id"]);
repers.Add(report);
}
return repers;

Oracle bulk insert via stored proc. taking too much time

I am tryign to do bulk inserts/updates efficiently from c# code to oracle database.
If I done it by statement, then it doesn’t take much time.
I am using the ODP.NET
Currently insert of 6000 records via below stored proc is taking 15 mins.
I have to use this stored proc, because it generates unique user_id.
Is this proc doing auto-commit ? Is there any autocommit setting I should turn off ?
Please suggest ways to do it efficiently.
CREATE OR REPLACE
PROCEDURE sbx_staging_insert_user(client IN varchar2,
username IN varchar2,
comm_type IN varchar2,
email_addr IN varchar2,
buddy_name IN varchar2,
--default_flag IN char,
user_id OUT INT)
AS
BEGIN
select sbx_staging_user_id_seq.nextval into user_id from dual;
insert into sbx_staging_user
(user_id,
client,
username,
comm_type,
email_addr,
buddy_name,
default_flag)
values
(user_id,
client,
username,
comm_type,
email_addr,
buddy_name,
'Y');
end sbx_staging_insert_user;
and C# code is:
cmd.Transaction = conn.BeginTransaction();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "sbx_staging_insert_user";
cmd.CommandType = CommandType.StoredProcedure;
var userClientParam = new OracleParameter(":client", OracleDbType.Varchar2);
var usernameParam = new OracleParameter(":username", OracleDbType.Varchar2);
var commTypeParam = new OracleParameter(":comm_type", OracleDbType.Varchar2);
var defaultParam = new OracleParameter(":default_flag", OracleDbType.Char) { Size = 1};
var emailParam = new OracleParameter(":email_addr", OracleDbType.Varchar2) { IsNullable = true };
var buddyParam = new OracleParameter(":buddy_name", OracleDbType.Varchar2) { IsNullable = true };
var userIdParam = new OracleParameter(":user_id", OracleDbType.Int32) { Direction = ParameterDirection.Output };
cmd.Parameters.Add(userClientParam);
cmd.Parameters.Add(usernameParam);
cmd.Parameters.Add(commTypeParam);
//cmd.Parameters.Add(defaultParam);
cmd.Parameters.Add(emailParam);
cmd.Parameters.Add(buddyParam);
cmd.Parameters.Add(userIdParam);
var cuList = new List<string>(Users.Count);
var uList = new List<string>(Users.Count);
var ctList = new List<string>(Users.Count);
var dfList = new List<char>(Users.Count);
var eaList = new List<string>(Users.Count);
var bnList = new List<string>(Users.Count);
var uiList = new List<decimal>(Users.Count);
int loopCnt = 0;
foreach (var ud in Users)
{
cuList.Add(ud.User.Client);
uList.Add(ud.User.Username);
ctList.Add(ud.User.CommType);
dfList.Add(ud.User.Default ? 'Y' : 'N');
eaList.Add(ud.User.Email);
bnList.Add(ud.User.BuddyName);
uiList.Add(-1);
}
userClientParam.Value = cuList.ToArray();
usernameParam.Value = uList.ToArray();
commTypeParam.Value = ctList.ToArray();
//defaultParam.Value = dfList.ToArray();
emailParam.Value = eaList.ToArray();
buddyParam.Value = bnList.ToArray();
userIdParam.Value = uiList.ToArray();
cmd.ArrayBindCount = cuList.Count;//Users.Count;//
cmd.ExecuteNonQuery();
cmd.Transaction.Commit();
Try something like this (untested, shortened for brevity):
public void insertRows()
{
if (Users.Count > 0)
{
OracleTransaction trans=_conn.BeginTransaction();
try
{
// create insert statement with bind vars
Stringbuilder sb = new Stringbuilder();
sb.Append("INSERT into sbx_staging_user(");
sb.Append("client,");
sb.Append("username,");
sb.Append("user_id");
sb.Append(") VALUES (");
sb.Append(":client,");
sb.Append(":username,");
sb.Append("seq_user_id.nextval");
sb.Append(") ");
OracleCommand cmd = new OracleCommand(sb.ToString(), _conn);
string[] ary_client = new string[Users.Count];
string[] ary_username = new string[Users.Count];
for (int i=0; i<Users.Count; i++)
{
User row=Users[i];
ary_client[i]=row.client;
ary_username[i]=row.username;
}
// prepare bind vars(bind in bulk using arrays)
OracleParameter prm=new OracleParameter();
cmd.Parameters.Clear();
cmd.ArrayBindCount=Users.Count;
cmd.BindByName=true;
prm=new OracleParameter("client", OracleDbType.Varchar2); prm.Value=ary_client; cmd.Parameters.Add(prm);
prm=new OracleParameter("username", OracleDbType.Varchar2); prm.Value=ary_username; cmd.Parameters.Add(prm);
cmd.ExecuteNonQuery();
trans.Commit();
trans.Dispose();
}
catch {
trans.Rollback();
trans.Dispose();
throw;
}
}
}
Maybe you should moove the bulk logic to the plsql.
See an example here:
http://dotnetslackers.com/articles/ado_net/BulkOperationsUsingOracleDataProviderForNETODPNET.aspx

Insert Query in C# using Parameters

Am trying to insert several columns into my database using the following insert query from C# but it throws the exception somehow somewhere and my guess is there are no values provided for insertion. i just want to confirm that and find out how i can fix the insert statement. i have a picture below that displays what is passed into the parameters at runtime. i used a break point to get this info.
need your expertise at this one...thanks
if (Page.IsValid)
{
DateTime exhibitDate = DateTime.Now;
int caseid = Convert.ToInt32(CaseIDDropDownList.SelectedItem.Text);
string exhibittype = exhibitTypeTextBox.Text.ToString();
string storedloc = storedLocationTextBox.Text.ToString();
string offid = DropDownList1.SelectedItem.Text.ToString();
Stream imgStream = exhibitImageFileUpload.PostedFile.InputStream;
int imgLen = exhibitImageFileUpload.PostedFile.ContentLength;
byte[] imgBinaryData = new byte[imgLen];
int n = imgStream.Read(imgBinaryData,0,imgLen);
try
{
SqlConnection connections = new SqlConnection(strConn);
SqlCommand command = new SqlCommand("INSERT INTO Exhibits (CaseID, ExhibitType, ExhibitImage, DateReceived, StoredLocation, InvestigationStatus, OfficerID, SuspectID, InvestigatorID, ManagerID, AdminID ) VALUES (#CaseID, #ExhibitType, #ExhibitImage, #DateReceived, #StoredLocation, #InvestigationStatus, #OfficerID, #SuspectID, #InvestigatorID, #ManagerID, #AdminID)", connections);
SqlParameter param0 = new SqlParameter("#CaseID", SqlDbType.Int);
param0.Value = caseid;
command.Parameters.Add(param0);
SqlParameter param1 = new SqlParameter("#ExhibitType", SqlDbType.NText);
param1.Value = exhibittype;
command.Parameters.Add(param1);
SqlParameter param2 = new SqlParameter("#ExhibitImage", SqlDbType.Image);
param2.Value = imgBinaryData;
command.Parameters.Add(param2);
SqlParameter param3 = new SqlParameter("#DateReceived", SqlDbType.SmallDateTime);
param3.Value = exhibitDate;
command.Parameters.Add(param3);
SqlParameter param4 = new SqlParameter("#StoredLocation", SqlDbType.NText);
param4.Value = storedloc;
command.Parameters.Add(param4);
SqlParameter param5 = new SqlParameter("#InvestigationStatus", SqlDbType.VarChar, 50);
param5.Value = "";
command.Parameters.Add(param5);
SqlParameter param6 = new SqlParameter("#OfficerID", SqlDbType.NChar, 10);
param6.Value = offid;
command.Parameters.Add(param6);
SqlParameter param7 = new SqlParameter("#SuspectID", SqlDbType.NChar, 10);
param7.Value = null;
command.Parameters.Add(param7);
SqlParameter param8 = new SqlParameter("#InvestigatorID", SqlDbType.NChar, 10);
param8.Value = null;
command.Parameters.Add(param8);
SqlParameter param9 = new SqlParameter("#ManagerID", SqlDbType.NChar, 10);
param9.Value = null;
command.Parameters.Add(param9);
SqlParameter param10 = new SqlParameter("#AdminID", SqlDbType.NChar, 10);
param10.Value = adminID;
command.Parameters.Add(param10);
connections.Open();
int numRowsAffected = command.ExecuteNonQuery();
connections.Close();
if (numRowsAffected != 0)
{
Response.Write("<BR>Rows Inserted successfully");
CaseIDDropDownList.ClearSelection();
exhibitTypeTextBox.Text = null;
storedLocationTextBox.Text = null;
DropDownList1.ClearSelection();
}
else
{
Response.Write("<BR>An error occurred uploading the image");
}
}
catch (Exception ex)
{
string script = "<script>alert('" + ex.Message + "');</script>";
}
the exception is as follows
$exception {"The parameterized query '(#CaseID int,#ExhibitType ntext,#ExhibitImage image,#DateReceive' expects the parameter '#SuspectID', which was not supplied."} System.Exception {System.Data.SqlClient.SqlException}
If you want to pass in NULL for your database / parameter type, you need to use DBNull.Value like this:
SqlParameter param9 = new SqlParameter("#ManagerID", SqlDbType.NChar, 10);
param9.Value = DBNull.Value;
command.Parameters.Add(param9);
Do this wherever you're setting something to null right now, and I'm pretty sure it'll work just fine. Everything is looking okay.
You can do this much easier, try it as such:
if (Page.IsValid)
{
DateTime exhibitDate = DateTime.Now;
int caseid = Convert.ToInt32(CaseIDDropDownList.SelectedItem.Text);
string exhibittype = exhibitTypeTextBox.Text.ToString();
string storedloc = storedLocationTextBox.Text.ToString();
string offid = DropDownList1.SelectedItem.Text.ToString();
Stream imgStream = exhibitImageFileUpload.PostedFile.InputStream;
int imgLen = exhibitImageFileUpload.PostedFile.ContentLength;
byte[] imgBinaryData = new byte[imgLen];
int n = imgStream.Read(imgBinaryData,0,imgLen);
try
{
SqlConnection connections = new SqlConnection(strConn);
SqlCommand command = new SqlCommand("INSERT INTO Exhibits (CaseID, ExhibitType, ExhibitImage, DateReceived, StoredLocation, InvestigationStatus, OfficerID, SuspectID, InvestigatorID, ManagerID, AdminID ) VALUES (#CaseID, #ExhibitType, #ExhibitImage, #DateReceived, #StoredLocation, #InvestigationStatus, #OfficerID, #SuspectID, #InvestigatorID, #ManagerID, #AdminID)", connections);
command.Parameters.AddWithValue("#CaseID", caseid);
//and so on for your 10 parameters
connections.Open();
int numRowsAffected = command.ExecuteNonQuery();
connections.Close();
if (numRowsAffected != 0)
{
Response.Write("<BR>Rows Inserted successfully");
CaseIDDropDownList.ClearSelection();
exhibitTypeTextBox.Text = null;
storedLocationTextBox.Text = null;
DropDownList1.ClearSelection();
}
else
{
Response.Write("<BR>An error occurred uploading the image");
}
}
catch (Exception ex)
{
string script = "<script>alert('" + ex.Message + "');</script>";
}
}
I'm not sure if this will actually fix what is happening without knowing the exact exception. If you could provide the actual exception that would help a lot.

Categories

Resources