Skip to content

一般结果集的获取

XuguConnection conn = new XuguConnection();
conn.ConnectionString = conn_xugu;

try
{
    conn.Open();
    XuguCommand cmd = new XuguCommand();
    cmd.Connection = conn;
    string sql_sql = "select * from ta";
    XuguDataAdapter da = new XuguDataAdapter(sql_sql, conn);
    DataSet ds = new DataSet();
    da.Fill(ds, "ta");
    for (int i = 0; i < ds.Tables[0].Rows.Count;i++ )
    {
        string val = "人员表数据: ";
        for (int j = 0; j < ds.Tables[0].Columns.Count;j++ )
        {
            val += ds.Tables[0].Rows[i][j].ToString()+"|";
        }
    }
    string sql_str2 = "select * from tp";
    XuguCommand cmd2 = conn.CreateCommand();// 或者 new DBCommand(sql_str, conn);
    cmd.CommandText = sql_str2;
    XuguDataReader reader = cmd.ExecuteReader();
    while (reader.Read())
    {
        string val = "人员数据: ";
        string id = reader.GetInt32(0).ToString();
        string pid = reader.GetString(1);
        string pname = reader.GetString(2);
        string desc = reader.IsDBNull(3) ? null : reader.GetString(3);
        string date = reader.GetDateTime(4).ToString();
        val += id + "|" + pid + "|" + pname + "|" + desc + "|" + date + "|";
        Console.WriteLine(val);
    }
}
catch (System.Exception ex)
{
    Console.WriteLine(ex.ToString());
    conn.Close();
    return 0;
}