Click here to Skip to main content
15,896,111 members

Comments by Tom Paul Heart (Top 1 by date)

Tom Paul Heart 8-May-19 5:00am View    
My Code:

try
{
SqlConnection conn = new SqlConnection(connStr);
SqlDataReader reader = null;

conn.Open();
string sql = "SELECT * FROM NEWS where NewsID= " + sid + "";


SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = sql;

reader = comm.ExecuteReader();

while (reader.Read())
{
string Newsid = reader.GetValue(reader.GetOrdinal("Newsid")).ToString();
string CatID = reader.GetValue(reader.GetOrdinal("CatID")).ToString();

string Title = reader.GetValue(reader.GetOrdinal("Title")).ToString();
string Content = reader.GetValue(reader.GetOrdinal("Content")).ToString();





if (Newsid != "")
{


SqlDataReader reader = null;
string sql = "SELECT CatID, CatName FROM Category order by Catid desc";

SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = sql;
reader = comm.ExecuteReader();

while (reader.Read())
{
string CatID_root = reader.GetValue(reader.GetOrdinal("CatID")).ToString();
string CatName = reader.GetValue(reader.GetOrdinal("CatName")).ToString();


if (CatID_root == CatID)
{

Dropdownlist.DataSource = reader;
Dropdownlist.DataValueField = "CatID";
Dropdownlist.DataTextField = "CatName";
Dropdownlist.SelectedValue = CatName;
Dropdownlist.DataBind();


}
else
{
Dropdownlist.DataSource = reader;
Dropdownlist.DataValueField = "id";
Dropdownlist.DataTextField = "bulkname";
Dropdownlist.DataBind();


}

}

}
}