I have this stored procedure
CREATE PROCEDURE [dbo].InsertUserTables
@UserName varchar(100),
@View varchar(30)
AS
INSERT INTO [dbo].[UserTables] (
[UserName],
[View]
)
VALUES (
@UserName,
@View
)
GO
and the C# code to insert a row
Code:
System.Data.SqlClient.SqlParameter [] arParams2 = new System.Data.SqlClient.SqlParameter[2];
arParams[0] = new System.Data.SqlClient.SqlParameter("@UserName", System.Data.SqlDbType.NVarChar, 100);
arParams[0].Value = "awni";
arParams[0].Direction = System.Data.ParameterDirection.Input;
arParams[1] = new System.Data.SqlClient.SqlParameter("@View", System.Data.SqlDbType.NVarChar, 30);
arParams[1].Value = "Cars";
arParams[1].Direction = System.Data.ParameterDirection.Input;
Insert("InsertUserTables", arParams);
..........
public void Insert(string szSPName, SqlParameter [] arParms)
{
// SqlConnection that will be used to execute the sql commands
SqlConnection connection = null;
connection = GetConnection(CGlobals.szConnectionString);
SqlCommand sqlCmd = new SqlCommand(szSPName, connection);
sqlCmd.CommandType = CommandType.StoredProcedure;
//sqlCmd.Connection.Open();
foreach (SqlParameter p in arParms)
{
if( p != null )
{
// Check for derived output value with no value assigned
if ( ( p.Direction == ParameterDirection.InputOutput ||
p.Direction == ParameterDirection.Input ) &&
(p.Value == null))
{
p.Value = DBNull.Value;
}
sqlCmd.Parameters.Add(p);
}
}
sqlCmd.ExecuteNonQuery();
connection.Close();
}
I've omitted the try/catch blocks here, but in the my code, I use them and
I get "Object must implement IConvertible" exception, what can I do? What
object is it talking about?
thanks
awni