Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for (int i = 1; i < Array_of_Sheet_Data.GetLength(0); i++)
                {

                   
                    byte[] arr = null;
                    byte[] arr2 = null;
                    byte[] varchar_arr = null;
                    .
                    .
                  
for (int k = 0; k < Array_of_Sheet_Data.GetLength(1); k++)
{
if (Array_of_Sheet_Data[0, k] == "char") //datat type checking
  {
    string s1 = Array_of_Sheet_Data[i, k];

string connectionString = "xxxxxxx";
  SqlConnection _con = new SqlConnection(connectionString);
   SqlCommand _cmd = new SqlCommand("ConvertCharToBinary", _con);
    _cmd.CommandType = CommandType.StoredProcedure;
      SqlParameter value = _cmd.Parameters.Add("@Value", SqlDbType.Char);
       value.Value = s1;
   SqlParameter return_value = _cmd.Parameters.Add("@returnValue", SqlDbType.Binary, 1000);
 return_value.Direction = ParameterDirection.Output;
  _con.Open();
 _cmd.ExecuteNonQuery();
 arr = (byte[])_cmd.Parameters["@returnValue"].Value;
  _con.Close();
           }

  if (Array_of_Sheet_Data[0, k] == "varchar") //datat type checking
 {
  string s1 = Array_of_Sheet_Data[i, k];
   string connectionString = "xxxxxxx";
    SqlConnection _con = new SqlConnection(connectionString);
SqlCommand _cmd = new SqlCommand("ConvertVarCharToBinary", _con);
_cmd.CommandType = CommandType.StoredProcedure;
    SqlParameter value = _cmd.Parameters.Add("@Value", SqlDbType.Char);
   value.Value = s1;
SqlParameter return_value = _cmd.Parameters.Add("@returnValue", SqlDbType.Binary, 1000);
return_value.Direction = ParameterDirection.Output;
 _con.Open();
 _cmd.ExecuteNonQuery();

                            varchar_arr = (byte[])_cmd.Parameters["@returnValue"].Value;


                            _con.Close();

                           
                        }

                        if (Array_of_Sheet_Data[0, k] == "tinyint")
                        {
                            dtype = Array_of_Sheet_Data[0, k].ToString();
                             int numVal = 0;
                            string s1 = Array_of_Sheet_Data[i, k];
                            numVal = byte.Parse(s1);
                            string connectionString = "xxxxxxx";
                            SqlConnection _con = new SqlConnection(connectionString);
                            SqlCommand _cmd = new SqlCommand("ConvertTinyIntToBinary", _con);
                            _cmd.CommandType = CommandType.StoredProcedure;
                            SqlParameter value = _cmd.Parameters.Add("@Value", SqlDbType.TinyInt);
                            value.Value = numVal;
                            SqlParameter return_value = _cmd.Parameters.Add("@returnValue", SqlDbType.Binary, 50);
                            return_value.Direction = ParameterDirection.Output;
                            _con.Open();
                            _cmd.ExecuteNonQuery();
                            tinyint_arr = (byte[])_cmd.Parameters["@returnValue"].Value;
                            _con.Close();

                        }

                       
			.
			.
			.
			.
}
}


am converting the values to binary using storeprocedures and getting return value
storing in byte array
based on the count i have created a temp table,i need a process to insert that byte arrays values into table
suggest me solution
Posted
Updated 6-Jan-12 2:36am
v5
Comments
Al Moje 6-Jan-12 5:08am    
correction on end tag </pre> location
darkDercane 6-Jan-12 8:41am    
why you use a stored procedure for that??
well the first i will check is the datatype of the columns that you are inserting are binary,and the review if the data obtained is well formed for parsing to a binary field. :P
pradeep manne 6-Jan-12 10:54am    
my target table column are of datatype binary
i need the insertion of that arrays ,or any other process

1 solution

Add a stored procedure for insert a binary type field.

SQL
CREATE PROCEDURE sp_InsertBinary
(@BinaryArray Binary)
AS
BEGIN
	INSERT INTO TABLE_OF_BINARY_FIELD VALUES(@BinaryArray)
END


Secondly, ensure that the Datatype that you are sending in your DataLayer are Binary, like this:
C#
SqlParameter sqlParam = new SqlParameter();
       sqlParam.DbType = System.Data.SqlDbType.Binary;
       sqlParam.Value = yourBinaryArray;


don't forget to add your parameter to your sqlcommand and execute them.

Greets :)
 
Share this answer
 
Comments
pradeep manne 7-Jan-12 4:28am    
hi, thanks for the reply
i need to insert the values into temp table which is created at run time based on the colums, i inserted the array values if i know the count i.s if 3 columns .but here i may create 4 cols,or 5 for that i nedd the insertion

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900