Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 0。这可能是因为Scope_标识的类型是bigint或其他数字数据类型。能否尝试转换.ToInt32(sqlparameter.Value)?@Philo这意味着您的RowId参数不是32位整数。您需要在这里指定类型以及sqlParameter.SqlDb_C#_Sql - Fatal编程技术网

C# 0。这可能是因为Scope_标识的类型是bigint或其他数字数据类型。能否尝试转换.ToInt32(sqlparameter.Value)?@Philo这意味着您的RowId参数不是32位整数。您需要在这里指定类型以及sqlParameter.SqlDb

C# 0。这可能是因为Scope_标识的类型是bigint或其他数字数据类型。能否尝试转换.ToInt32(sqlparameter.Value)?@Philo这意味着您的RowId参数不是32位整数。您需要在这里指定类型以及sqlParameter.SqlDb,c#,sql,C#,Sql,0。这可能是因为Scope_标识的类型是bigint或其他数字数据类型。能否尝试转换.ToInt32(sqlparameter.Value)?@Philo这意味着您的RowId参数不是32位整数。您需要在这里指定类型以及sqlParameter.SqlDbType=SqlDbType.Int;比如,如果它是十进制的,你需要把这两个都改成十进制。没有错误。类型是int。。。但最后,所有的newRowID=0。。。。虽然它应该是130…是的,但出于好奇…我想让这种方法也能工作。:)这可能是因为Sco


0。这可能是因为Scope_标识的类型是bigint或其他数字数据类型。能否尝试转换.ToInt32(sqlparameter.Value)?@Philo这意味着您的RowId参数不是32位整数。您需要在这里指定类型以及sqlParameter.SqlDbType=SqlDbType.Int;比如,如果它是十进制的,你需要把这两个都改成十进制。没有错误。类型是int。。。但最后,所有的newRowID=0。。。。虽然它应该是130…是的,但出于好奇…我想让这种方法也能工作。:)这可能是因为Scope_标识的类型是bigint或其他数字数据类型。能否尝试转换.ToInt32(sqlparameter.Value)?@Philo这意味着您的RowId参数不是32位整数。您需要在这里指定类型以及sqlParameter.SqlDbType=SqlDbType.Int;比如,如果它是十进制的,你需要把这两个都改成十进制。没有错误。类型是int。。。但最后,所有的newRowID=0。。。。虽然应该是130……是的,但出于好奇……我想让这种方法也能起作用。:)
Int32 newRowID = 0;

    // -------------------------------------------------------------------- //
    // SQL Query-1: to store validated information in the Enrollment table. //
    // -------------------------------------------------------------------- //
    SqlConnection Connection = new SqlConnection(xxx_DBConnect.SqlServerConnection);

    String strSQL = " OPEN SYMMETRIC KEY zzzzzzzKey DECRYPTION BY CERTIFICATE zzzzzzzCertificate1"
        + " INSERT INTO [xxx].[dbo].[yyy]"
        + " (Type, Name, DBA, Address1, City, State, Zip, TIN, TINLast4, NPI)"
        + " values (@Type, @Name, @DBA, @Address1, @rCity, @State, @Zip, ENCRYPTBYKEY(KEY_GUID('zzzzzzz'),CONVERT(VARCHAR, @TIN)), @TINLast4, @rNPI)"
        + " CLOSE SYMMETRIC KEY zzzzzzzKey;"
        + " SET @RowId = SCOPE_IDENTITY();";

    // Connection is explicitly opened.
    Connection.Open();

    SqlCommand command = new SqlCommand(strSQL, Connection);

    SqlParameter parameter = new SqlParameter();
    parameter.ParameterName = "@RowId";
    parameter.SqlDbType = SqlDbType.Int;
    parameter.Direction = ParameterDirection.Output;
    command.Parameters.Add(parameter);


    command.Parameters.AddWithValue("@Type", _type);
    command.Parameters.AddWithValue("@Name", _Name);
    command.Parameters.AddWithValue("@DBA", _DBA);
    command.Parameters.AddWithValue("@Address1", _address);
    command.Parameters.AddWithValue("@City", _city);
    command.Parameters.AddWithValue("@State", _state);
    command.Parameters.AddWithValue("@Zip", _zip);
    command.Parameters.AddWithValue("@TIN", _tIN);
    command.Parameters.AddWithValue("@TINLast4", _TINlast4);
    command.Parameters.AddWithValue("@NPI", _nPI);

    //newRowID = (Int32)command.ExecuteScalar();// <--- how do I write this in the correct syntax ?? ....

    command.ExecuteNonQuery();


    if (parameter.Value != DBNull.Value)
        {
            newRowID = (int)parameter.Value;
        }


    Connection.Close();
SqlParameter parameter = new SqlParameter();
parameter.ParameterName = "@RowId";
parameter.SqlDbType = SqlDbType.Decimal; 
parameter.Direction = ParameterDirection.Output;

command.Parameters.Add(parameter);


command.ExecuteNonQuery();
if (parameter.Value!=DbNull.Value)
{
   newRowID = (Int32) parameter.Value;
}
SqlParameter sqlParameter = new SqlParameter();
sqlParameter.ParameterName = "@RowId";
sqlParameter.SqlDbType = SqlDbType.Int;
sqlParameter.Direction = ParameterDirection.Output;

command.Parameters.Add(sqlParameter);
declare @RowId int;
if(sqlParameter.Value != DBNull.Value)
   newRowID  = (Int32)sqlParameter.Value;
 String strSQL = " OPEN SYMMETRIC KEY zzzzzzzKey DECRYPTION BY CERTIFICATE zzzzzzzCertificate1"
        + " INSERT INTO [xxx].[dbo].[yyy]"
        + " (Type, Name, DBA, Address1, City, State, Zip, TIN, TINLast4, NPI)"
        + " values (@Type, @Name, @DBA, @Address1, @rCity, @State, @Zip, ENCRYPTBYKEY(KEY_GUID('zzzzzzz'),CONVERT(VARCHAR, @TIN)), @TINLast4, @rNPI)"
        + " CLOSE SYMMETRIC KEY zzzzzzzKey;"
        + " SELECT SCOPE_IDENTITY();";
 SELECT CONVERT(int, SCOPE_IDENTITY());
int newRowID = (int)command.ExecuteScalar();