okay so i am pretty new to coding and i got a school project which one of the requirements was to be able to search a database and show the results in a table so this is the code i wrote for this:
aspx page:
<form id="userSearchForm" method="post" action="#">
<input type="text" id="userName" value="" />
<input class="button" id="submit" name="submit" type="submit" value="Submit" />
</form>
<%=st %>
aspx.cs page:
public partial class Default2 : System.Web.UI.Page
{
public string st=null;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["submit"] != null)
{
string user = Request.Form["userName"];
st = MyAdoHelper.printDataTable("Database.mdf", "select * from members where name = '" + user + "'");
}
}
}
and a code i use in a different c# page that i call in the aspx.cs page above:
public static DataTable ExecuteDataTable(string fileName, string sql)
{
SqlConnection conn = ConnectToDb(fileName);
conn.Open();
SqlDataAdapter tableAdapter = new SqlDataAdapter(sql,conn);
DataTable dt = new DataTable();
tableAdapter.Fill(dt);
return dt;
}
public static string printDataTable(string fileName, string sql)
{
DataTable dt = ExecuteDataTable(fileName, sql);
string printStr = "<table border='1'>";
foreach (DataRow row in dt.Rows)
{
printStr += "<tr>";
foreach (object myItemArray in row.ItemArray)
{
printStr += "<td>" + myItemArray.ToString() +"</td>";
}
printStr += "</tr>";
}
printStr += "</table>";
return printStr;
}
basically after i press submit what seems to be a blank table appears - a big black line across the screen as if it is the border of a table with out information. any help?