string output = "";
int debugColnumber = 0;
int debugRecordnumber = 0;
using (SqlConnection cn = new SqlConnection(DBConnection.getDBConnection()))
{
SqlCommand cmd = new SqlCommand(sql, cn);
cmd.CommandType = System.Data.CommandType.Text;
try
{
cn.Open();
SqlDataReader reader = cmd.ExecuteReader();
var columns = new List<string>();
output = "<table><tr>";
for (int i = 0; i < reader.FieldCount; i++)
{
columns.Add(reader.GetName(i));
output += "<th>" + reader.GetName(i) + "</th>";
}
output += "</tr>";
while (reader.Read())
{
debugRecordnumber++;
output += "<tr>";
for (int i = 0; i < reader.FieldCount; i++)
{
debugColnumber++;
var dotNetType = reader.GetFieldType(i).Name;
var sqlType = reader.GetDataTypeName(i);
var myType = reader.GetType().ToString();
if (reader.IsDBNull(i))
{
output += "<td></td>";
}
else
{
switch (reader.GetFieldType(i).Name)
{
case "Boolean":
output += "<td>" + reader.GetBoolean(i).ToString() + "</td>";
break;
case "String":
output += "<td>" + reader.GetString(i) + "</td>";
break;
case "Double":
output += "<td>" + reader.GetDouble(i).ToString() + "</td>";
break;
case "Decimal":
output += "<td>" + reader.GetDecimal(i).ToString() + "</td>";
break;
case "Date":
//todo
break;
case "int":
//todo
break;
default:
output += "<td>" + reader.GetFieldType(i).Name + "</td>";
break;
}
}
}
output += "</tr>";
}
output += "</table>";
No comments:
Post a Comment