//在TIPTOP中的操作,使用ODBC數據源連接INFORMIX,其他大同小異
/*Select*/
private DataTable OdbcSelect_ndsf(string sql)
{
OdbcConnection objOdbcConnection=new OdbcConnection(strOdbcConnection_ndsf);
objOdbcConnection.Open();
string strOdbcCommand2=sql;
OdbcCommand objOdbcCommand=new OdbcCommand(strOdbcCommand2,objOdbcConnection);
OdbcDataAdapter objOdbcDataAdapter=new OdbcDataAdapter(objOdbcCommand);
DataSet DS=new DataSet();
objOdbcDataAdapter.Fill(DS);
DataTable dtb=DS.Tables[0];
objOdbcConnection.Close();
return dtb;
}
/*Update*/
private void OdbcUpdate_ndsf(string sql)
{
OdbcConnection objOdbcConnection=new OdbcConnection(strOdbcConnection_ndsf);
objOdbcConnection.Open();
string strOdbcCommand2=sql;
OdbcCommand objOdbcCommand=new OdbcCommand(strOdbcCommand2,objOdbcConnection);
objOdbcCommand.ExecuteNonQuery();
}
一般性SQL方法
--------------------------------------------
假设有存储过程如下:
---------------------------------------------
CREATE proc sp_uptmp @tmpName varchar(50),@srcPos varchar(255)
as
Begin TRAN
insert into t_template values(@tmpName,@srcPos)
COMMIT
return isnull(@@identity,0)
GO
------------------------------------------------------------
在 ado.net 里面获取返回值的方法为(c#):
------------------------------------------------------------
SqlConnection dbconn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("sp_uptmp",dbconn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter tmpName = cmd.Parameters.Add("@tmpName",SqlDbType.VarChar);
SqlParameter srcPos = _cmd.Parameters.Add("@srcPos",SqlDbType.VarChar);
SqlParameter rtnval = cmd.Parameters.Add("rval",SqlDbType.Int);
tmpName.Direction = ParameterDirection.Input;
srcPos.Direction = ParameterDirection.Input;
rtnval.Direction = ParameterDirection.ReturnValue;
tmpName.Value = "";
srcPos.Value = "";
dbconn.Open();
cmd.ExecuteNonQuery();
dbconn.Close();
tmpid = (int)rtnval.Value; //此处即为返回值