我正致力于从使用MySQL作为数据库的云服务器检索数据。我可以检索数据但是我想格式化命令提示符以显示具有给定记录数的5列。这是一个例子:
-------------------------------------------------------------------------
| ITEM | QUANT | SIZE | COLOR | PRICE |
-------------------------------------------------------------------------
| | | | | |
| | | | | |
| | | | | |
-------------------------------------------------------------------------
以下是我目前正在使用的代码&感谢任何人的帮助:
//Loop through all data results
foreach (DataRow dataRow in theTable.Rows)
{
Console.WriteLine("[ITEM]");
Console.WriteLine ("--------------------------------------------------------------------------------");
using (OdbcConnection con = new OdbcConnection(conString))
{
con.Open();
using (OdbcCommand com = new OdbcCommand("SELECT invent_desc, qoh int, itemsize, color, curr_price FROM item,inventory", con))
{
using (OdbcDataReader oReader = com.ExecuteReader())
{
while (oReader.Read())
Console.WriteLine(oReader[0] + " " + oReader[1] + " " + oReader[2] + " " + ((decimal)oReader[3]) + " " + oReader[4]);
}//end using reader
}//end usin
新编辑下面的宣传片可以运作,但遗憾的是它确实不能很好地组织表格。有人还能帮忙吗?
答案 0 :(得分:0)
更新:
using (OdbcConnection con = new OdbcConnection(conString)) {
con.Open();
using (OdbcCommand com = new OdbcCommand("SELECT * FROM item,inventory", con)) {
using (OdbcDataReader oReader = com.ExecuteReader()) {
while (oReader.Read())
Console.WriteLine(oReader[0] + " " + oReader[1] + " " + oReader[2] + " " + oReader[3]+ " " + oReader[4]);
}//end using reader
}//end usin
我建议你做这样的事情
Console.WriteLine(oReader[0] + " " + oReader[1] + " " + oReader[2] + " " + oReader[3]+ " " + oReader[4]);
上面会给你o / p