Invalid object name - c#

The first one is function with query to access information about driver from table tblDDDDriver by using VehicleNumber which is one of the field or column name in tblDDDDriver.
The second one is what i coded to access that function.
Now when i click the button i shows the error Invalid object name 'tblDDDDriver'
public DataTable GetDriverByVehicalNumber(string VehicleNumber)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB; Integrated Security=True; Initial Catalog=tprojectDB;");
string sql = "select *from tblDDDDriver where VehicleNumber=#VehicleNumber";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("#VehicleNumber", VehicleNumber);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
private void button6_Click(object sender, EventArgs e)
{
DataTable dt = dc.GetDriverByVehicalNumber(txtvehicleno.Text);
if (dt.Rows.Count > 0)
{
txtlicenseno.Text = dt.Rows[0]["LicenseNumber"].ToString();
txtlicensecategory.Text = dt.Rows[0]["LicenseCategory"].ToString();
txtissuedate.Text = dt.Rows[0]["IssueDate"].ToString();
txtrenewdate.Text = dt.Rows[0]["RenewDate"].ToString();
txtfullname.Text = dt.Rows[0]["FullName"].ToString();
txtdob.Text = dt.Rows[0]["DOB"].ToString();
txtaddress.Text = dt.Rows[0]["Address"].ToString();
string gender = dt.Rows[0]["Gender"].ToString();
if (gender == "Male")
{
txtgender.Text = " MALE";
}
else
{
txtgender.Text = "FEMALE";
}
txtvehicleno.Text = dt.Rows[0]["VehicleNumber"].ToString();
txthealthstaus.Text = dt.Rows[0]["HealthStatus"].ToString();
txtdrivertype.Text = dt.Rows[0]["DriverType"].ToString();
Image img;
byte[] bytimg = (byte[])dt.Rows[0]["Image"];
//convert byte of imagedate to Image format
using (MemoryStream ms = new MemoryStream(bytimg, 0, bytimg.Length))
{
ms.Write(bytimg, 0, bytimg.Length);
img = Image.FromStream(ms, true);
pictureBox1.Image = img;
}
}
DataTable dd = dc.GetMaxDeathNo(Convert.ToDecimal(txtlicensenumber.Text));
if (dd.Rows.Count > 0)
{
txtdeathaccidentno.Text = dd.Rows[0]["DeathNumber"].ToString();
}
DataTable dM = dc.GetMaxMajorNo(Convert.ToDecimal(txtlicensenumber.Text));
if (dM.Rows.Count > 0)
{
txtmajoraccidentno.Text = dM.Rows[0]["MajorNumber"].ToString();
}
DataTable dm = dc.GetMaxMinorNo(Convert.ToDecimal(txtlicensenumber.Text));
if (dm.Rows.Count > 0)
{
txtminoraccidentno.Text = dm.Rows[0]["MinorNumber"].ToString();
}
DataTable dtrb = dc.GetTrafficRuleBroken(Convert.ToDecimal(txtlicensenumber.Text));
{
dataGridView1.DataSource = dtrb;
}
}

Related

How to remain the treeview after redirect to another page?

Im currently using this method to bind my treeview, After i expand the treeview and click the node, it will redirect to another page, and then the treeview will be refresh to default, which means showing the treeview before expanding.. so i need to save the treeview state in order to remain the treeview state. i had tried the below method but it's not working, anyone can help..
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadTransactionMenu();
if (Session["ExpandedNodes"] != null)
((List<string>)Session["ExpandedNodes"]).ForEach(a => TreeView1.FindNode(a).Expanded = true);
}
}
private void LoadTransactionMenu()
{
//TRANSACTION MENU
string SubModuleID, SubModuleNM, DocModuleID, DocModuleName, MenuTransID, MenuTransName;
SqlConnection con = new SqlConnection(ConString);
string CmdString = "SELECT SUBMODULEID, SUBMODULENM, URLNAME FROM SUBMODULE";
SqlCommand cmd = new SqlCommand(CmdString, con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
TreeNode node1 = new TreeNode();
node1.Text = "TRANSACTION MENU";
TreeView1.Nodes.Add(node1);
for (int i = 0; i < dt.Rows.Count; i++)
{
SubModuleID = dt.Rows[i]["SUBMODULEID"].ToString();
SubModuleNM = dt.Rows[i]["SUBMODULENM"].ToString();
TreeNode SubModuleNode = new TreeNode(SubModuleNM, SubModuleID);
SubModuleNode.NavigateUrl = dt.Rows[i]["URLNAME"].ToString();
node1.ChildNodes.Add(SubModuleNode);
CmdString = "SELECT DDID, DOCNAME, DDADDRESS FROM DOCMODULE WHERE SUBMODULEID=#SUBMODULEID";
cmd = new SqlCommand(CmdString, con);
cmd.Parameters.AddWithValue("#SUBMODULEID", SubModuleID);
sda = new SqlDataAdapter(cmd);
DataTable dt2 = new DataTable();
sda.Fill(dt2);
for (int j = 0; j < dt2.Rows.Count; j++)
{
DocModuleID = dt2.Rows[j]["DDID"].ToString();
DocModuleName = dt2.Rows[j]["DOCNAME"].ToString();
TreeNode DocModuleNode = new TreeNode(DocModuleName, DocModuleID);
DocModuleNode.NavigateUrl = dt2.Rows[j]["DDADDRESS"].ToString();
SubModuleNode.ChildNodes.Add(DocModuleNode);
CmdString = "SELECT DID, DNAME, DADDRESS FROM MENUTRANSACTION WHERE DDID=#DDID AND UID= '" + Session["UserID"] + "'";
cmd = new SqlCommand(CmdString, con);
cmd.Parameters.AddWithValue("#DDID", DocModuleID);
sda = new SqlDataAdapter(cmd);
DataTable dt3 = new DataTable();
sda.Fill(dt3);
for (int k = 0; k < dt3.Rows.Count; k++)
{
MenuTransID = dt3.Rows[k]["DID"].ToString();
MenuTransName = dt3.Rows[k]["DNAME"].ToString();
TreeNode MenuTransNode = new TreeNode(MenuTransName, MenuTransID);
MenuTransNode.NavigateUrl = dt3.Rows[k]["DADDRESS"].ToString();
DocModuleNode.ChildNodes.Add(MenuTransNode);
}
if (DocModuleNode.ChildNodes.Count == 0)
{
SubModuleNode.ChildNodes.Remove(DocModuleNode);
}
}
if (SubModuleNode.ChildNodes.Count == 0)
{
node1.ChildNodes.Remove(SubModuleNode);
}
}
}
public void GetExpandedStatus(TreeNode node, List<string> ExpandedNodes)
{
//check if node is expanded
if (node.Expanded.GetValueOrDefault(false))
ExpandedNodes.Add(node.ValuePath);
node.ChildNodes.Cast<TreeNode>().ToList().ForEach(a => GetExpandedStatus(a, ExpandedNodes));
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
List<string> expandedNodes = new List<string>();
//get all expanded nodes
TreeView1.Nodes.Cast<TreeNode>().ToList().ForEach(a => GetExpandedStatus(a, expandedNodes));
//collapse all to reset the treeview
TreeView1.CollapseAll();
//save expanded node value paths
Session["ExpandedNodes"] = expandedNodes;
}

Set value of combo box to collected value from source

I have a form with two combo boxes which both have a list from a database. In this case one is a list of countries and based on the value selected there, the second list is updated to show only the cities that belong to the selected country. After that, the values are combined and stored in my program like "city, country".
When I open my form I retrieve that information and separate the values back to just country and city. All working. The trouble I have now is that the comboboxes should display the retrieved values if the correspond to a value found in the list/database. I tried as shown below, but that is not working. I guess it has something to do with adding a new row to the database to show "--Select Country--" and "--Select City--".
I hope you can point me in the right direction. Thank you all in advance for your replies.
comboBoxCountry.SelectedValue = comboBoxCountry.FindString(country);
comboBoxCity.SelectedValue = comboBoxCity.FindString(city);
public partial class FormPropertyEditor : Form
{
//Connect to local database.mdf
SqlConnection con = new SqlConnection("Data Source = (LocalDB)\\MSSQLLocalDB;AttachDbFilename=" +
#"C:\Users\gleonvanlier\AppData\Roaming\Autodesk\ApplicationPlugins\MHS Property Editor\Database.mdf;" +
"Integrated Security=True;Connect Timeout=30;User Instance=False;");
DataRow dr;
public FormPropertyEditor()
{
InitializeComponent();
ReadProperties();
refreshdata();
}
public void refreshdata()
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from TblCountries Order by CountryName", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
dr = dt.NewRow();
dr.ItemArray = new object[] { 0, "--Select Country--" };
dt.Rows.InsertAt(dr, 0);
comboBoxCountry.ValueMember = "CountryID";
comboBoxCountry.DisplayMember = "CountryName";
comboBoxCountry.DataSource = dt;
comboBoxCountry.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBoxCountry.AutoCompleteSource = AutoCompleteSource.ListItems;
}
private void comboBoxCountry_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBoxCountry.SelectedValue.ToString() != null)
{
int CountryID = Convert.ToInt32(comboBoxCountry.SelectedValue.ToString());
refreshstate(CountryID);
}
}
public void refreshstate(int CountryID)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from TblCities where CountryID= #CountryID Order by CityName", con);
cmd.Parameters.AddWithValue("CountryID", CountryID);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
dr = dt.NewRow();
dr.ItemArray = new object[] { 0, 0, "--Select City--" };
dt.Rows.InsertAt(dr, 0);
comboBoxCity.ValueMember = "CityID";
comboBoxCity.DisplayMember = "CityName";
comboBoxCity.DataSource = dt;
comboBoxCity.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBoxCity.AutoCompleteSource = AutoCompleteSource.ListItems;
}
private void ReadProperties()
{
string progId = "Inventor.Application";
Type inventorApplicationType = Type.GetTypeFromProgID(progId);
Inventor.Application invApp = (Inventor.Application)Marshal.GetActiveObject(progId);
//Get the active document in Inventor
Document oDoc = (Document)invApp.ActiveDocument;
ReadProperties readProperties = new ReadProperties();
//Read Customer
string txtCustomer = readProperties.ReadCustomProperty("Customer", oDoc).ToString();
this.textBoxCustomer.Text = txtCustomer;
//Read Location
string txtLocation = readProperties.ReadCustomProperty("Location", oDoc).ToString();
try
{
string[] location = txtLocation.Split(',', ' ');
string city = location[0];
string country = location[1];
comboBoxCountry.SelectedValue = comboBoxCountry.FindString(country);
comboBoxCity.SelectedValue = comboBoxCity.FindString(city);
}
catch (Exception e)
{
string city = string.Empty;
string country = string.Empty;
}
}
This solved it:
comboBoxCountry.SelectedIndex = comboBoxCountry.FindStringExact(country);
comboBoxCity.SelectedIndex = comboBoxCity.FindStringExact(city);

GridView_RowUpdating method doesn't works in my asp.net project

I have an asp.net project, in which columns in GridView adding manually by button click, here's the method:
protected void addVacations_Click(object sender, EventArgs e)
{
using (var conn = new NpgsqlConnection(connStr))
{
conn.Open();
NpgsqlCommand cmd = new NpgsqlCommand("insert into vacations(id,name,date,nodes) values(DEFAULT, #imya, #data, #primVac)", conn);
cmd.Parameters.Add(new NpgsqlParameter("#imya", imya.Text));
cmd.Parameters.Add(new NpgsqlParameter("#data", data.Text));
cmd.Parameters.Add(new NpgsqlParameter("#primVac", primVac.Text));
cmd.ExecuteNonQuery();
Response.Redirect(Request.RawUrl);
}
}
I have two others buttons, that adding change GridView's columns by clicking them.
Now i have to add opportunity to change them online by clients. Here's the GridView code:
<asp:GridView ID="GridView1" runat="server" DataKeyNames="id" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="1650px" AutoGenerateDeleteButton="True" OnRowDeleting="GridView1_RowDeleting" OnRowUpdating="GridView1_RowUpdating" OnRowEditing="GridView1_RowEditing" AutoGenerateEditButton="True" >
Here's GridView1_RowUpdating method:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView1.Rows[e.RowIndex];
int ID5 = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);
string name = (row.FindControl("name") as TextBox).Text;
string date = (row.FindControl("date") as TextBox).Text;
string prim = (row.FindControl("nodes") as TextBox).Text;
string constr = ConfigurationManager.ConnectionStrings["postgresConnectionString"].ConnectionString;
using (NpgsqlConnection cn = new NpgsqlConnection(constr))
{
string query = "UPDATE vacations SET name=#name,date=#date,nodes=#prim Where id=#ID5";
NpgsqlCommand cmd = new NpgsqlCommand(query, cn);
cmd.Parameters.Add("#name", NpgsqlDbType.Varchar).Value = name;
cmd.Parameters.Add("#date", NpgsqlDbType.Varchar).Value = date;
cmd.Parameters.Add("#nodes", NpgsqlDbType.Varchar).Value = prim;
cmd.Parameters.Add("#id", NpgsqlDbType.Integer).Value = ID5;
cn.Open();
cmd.ExecuteNonQuery();
}
}
Right now i have next error when trying to change rows:
Server error in the application '/'.
The object reference does not point to an instance of the object.
Description: An unhandled exception occurred during the execution of the current web request. Examine the stack trace for more information about this error and the code snippet that caused it.
Exception Information: System.NullReferenceException: The object reference does not point to an instance of the object.
Source error:
Line 361: GridViewRow row = GridView1.Rows[e.RowIndex];
Line 362: int ID5 = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);
Line 363: string name = (row.FindControl("name") as TextBox).Text;
The problem exactly in Line 363
I think the problem in my string, if be exact here:
string name = (row.FindControl("name") as TextBox).Text;
string date = (row.FindControl("date") as TextBox).Text;
string prim = (row.FindControl("nodes") as TextBox).Text;
So i need help how to correctly declare my strings? Or what wrong in my code.
Update. Here is my column details, all three buttons:
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSource = null;//надо удалить текущие колонны (columns)
GridView1.DataBind();
for (int i = 0; GridView1.Columns.Count > i;)
{
GridView1.Columns.RemoveAt(i);
}
using (var conn = new NpgsqlConnection(connStr))
{
conn.Open();
bf1.HeaderText = "Направление деятельности";
bf1.DataField = "lineofbusiness";
bf1.ReadOnly = true;
bf1.SortExpression = "Napr";
bf2.HeaderText = "Объект";
bf2.DataField = "object";
bf2.SortExpression = "Obj";
bf3.HeaderText = "Мероприятия";
bf3.DataField = "events";
bf3.SortExpression = "Merop";
bf4.HeaderText = "Срок";
bf4.DataField = "deadline";
bf4.SortExpression = "Srok";
bf5.HeaderText = "Примечания";
bf5.DataField = "nodes";
bf5.SortExpression = "Prim";
GridView1.Columns.Add(bf1);
GridView1.Columns.Add(bf2);
GridView1.Columns.Add(bf3);
GridView1.Columns.Add(bf4);
GridView1.Columns.Add(bf5);
NpgsqlCommand cmd = new NpgsqlCommand();
NpgsqlDataAdapter sqlDa = new NpgsqlDataAdapter("SELECT id, lineofbusiness, object, events, deadline, nodes FROM mainpage where executor = '" + (string)Session["Name"] + "' ", conn);
//NpgsqlDataAdapter sqlDa1 = new NpgsqlDataAdapter("SELECT lineofbusiness, object, events, deadline, nodes FROM mainpage where executor = '" + curentExec + "' ", conn); //показ по исполнителю(раб код)
DataTable dtbl = new DataTable();
sqlDa.Fill(dtbl);
GridView1.DataSource = dtbl;
GridView1.DataBind();
Panel2.Visible = false;
Panel1.Visible = true;
Panel3.Visible = false;
//conn.Close(); //надо ли?
}
}
protected void Button2_Click(object sender, EventArgs e)
{
GridView1.DataSource = null;//надо удалить текущие колонны (columns)
GridView1.DataBind();
for (int i = 0; GridView1.Columns.Count > i;)
{
GridView1.Columns.RemoveAt(i);
}
using (var conn = new NpgsqlConnection(connStr))
{
conn.Open();
bf1.HeaderText = "Номер";
bf1.DataField = "id";
bf1.ReadOnly = true;
bf1.SortExpression = "11";
//bf2.HeaderText = "ФИО";
//bf2.DataField = "name";
//bf2.SortExpression = "22";
bf3.HeaderText = "Место";
bf3.DataField = "place";
bf3.SortExpression = "33";
bf4.HeaderText = "Цель";
bf4.DataField = "target";
bf4.SortExpression = "44";
bf5.HeaderText = "Срок";
bf5.DataField = "date";
bf5.SortExpression = "44";
bf6.HeaderText = "Результат";
bf6.DataField = "result";
bf6.SortExpression = "44";
GridView1.Columns.Add(bf1);
GridView1.Columns.Add(bf2);
GridView1.Columns.Add(bf3);
GridView1.Columns.Add(bf4);
GridView1.Columns.Add(bf5);
GridView1.Columns.Add(bf6);
NpgsqlCommand cmd = new NpgsqlCommand();
//NpgsqlDataAdapter sqlDavac = new NpgsqlDataAdapter("SELECT * FROM trips", conn);
NpgsqlDataAdapter sqlDavac = new NpgsqlDataAdapter("SELECT id, place, target, date, result FROM trips where name = '" + (string)Session["Name"] + "' ", conn);
DataTable dtblvac = new DataTable();
sqlDavac.Fill(dtblvac);
GridView1.DataSource = dtblvac;
GridView1.DataBind();
Panel1.Visible = false;
Panel2.Visible = false;
Panel3.Visible = true;
}
}
protected void Button3_Click(object sender, EventArgs e)
{
GridView1.DataSource = null;//надо удалить текущие колонны (columns)
GridView1.DataBind();
for (int i = 0; GridView1.Columns.Count > i;)
{
GridView1.Columns.RemoveAt(i);
}
using (var conn = new NpgsqlConnection(connStr))
{
conn.Open();
bf1.HeaderText = "Номер";
bf1.DataField = "id";
bf1.ReadOnly = true;
bf1.SortExpression = "NomerVac";
//bf2.HeaderText = "ФИО";
//bf2.DataField = "name";
//bf2.SortExpression = "NameVac";
bf3.HeaderText = "Дата";
bf3.DataField = "date";
bf3.SortExpression = "DataVac";
bf4.HeaderText = "Примечания";
bf4.DataField = "nodes";
bf4.SortExpression = "PrimVac";
GridView1.Columns.Add(bf1);
GridView1.Columns.Add(bf2);
GridView1.Columns.Add(bf3);
GridView1.Columns.Add(bf4);
NpgsqlCommand cmd = new NpgsqlCommand();
//NpgsqlDataAdapter sqlDavac = new NpgsqlDataAdapter("SELECT * FROM vacations", conn);
NpgsqlDataAdapter sqlDavac = new NpgsqlDataAdapter("SELECT id, date, nodes FROM vacations where name = '" + (string)Session["Name"] + "' ", conn);
DataTable dtblvac = new DataTable();
sqlDavac.Fill(dtblvac);
GridView1.DataSource = dtblvac;
GridView1.DataBind();
Panel1.Visible = false;
Panel2.Visible = true;
Panel3.Visible = false;
}
}

how to display comparison chart using ajax

I am trying to display ajax bar chart in my web page. But it is only displaying one value .
My db contains 3 columns(name, credit, debit) I want to display the credit debit values in chart. But the chart is only displaying one value. How can I modify the given below coding. Thank you.
Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string query = "select Name from aTable";
DataTable dt = GetData(query);
ddlCountries.DataSource = dt;
ddlCountries.DataTextField = "Name";
ddlCountries.DataValueField = "Name";
ddlCountries.DataBind();
ddlCountries.Items.Insert(0, new ListItem("Select", ""));
}
}
private DataTable GetData(string query, SqlParameter[] prms = null)
{
DataTable dt = new DataTable();
string constr = ConfigurationManager.ConnectionStrings["demoConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
if (prms != null)
cmd.Parameters.AddRange(prms);
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
}
}
return dt;
}
}
protected void ddlCountries_SelectedIndexChanged(object sender, EventArgs e)
{
string query = "select Name, Debit, Credit From aTable where Name=#Name";
SqlParameter[] prms = new SqlParameter[1];
prms[0] = new SqlParameter("#name", SqlDbType.NVarChar);
prms[0].Value = ddlCountries.SelectedItem.Value.ToString();
DataTable dt = GetData(query, prms);
string[] x = new string[dt.Rows.Count];
decimal[] y = new decimal[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][0].ToString();
y[i] = Convert.ToInt32(dt.Rows[i][1]);
}
BarChart1.Series.Add(new AjaxControlToolkit.BarChartSeries { Data = y });
BarChart1.CategoriesAxis = string.Join(",", x);
BarChart1.ChartTitle = string.Format("{0} -RunTimeReportChart", ddlCountries.SelectedItem.Value);
if (x.Length > 3)
{
BarChart1.ChartWidth = (x.Length * 100).ToString();
}
BarChart1.Visible = ddlCountries.SelectedItem.Value != "";
}
Data Base:
Actual Output:
The given below chart is only displaying the name and debit value. I want to display the credit value also. Please help me.
Something Like :
decimal[] z = new decimal[dt.Rows.Count];
z[i] = Convert.ToInt32(dt.Rows[i][2]);
BarChart1.Series.Add(new AjaxControlToolkit.BarChartSeries { Data = z });

how i get limited latest 6 rows from table

i am trying to retrieve latest 6 rows from my database table ,i am using max value but how
i get limited 6 rows from table and that retrieved result to use in for loop,to display hyperlinks in panel
protected void Page_Load(object sender, EventArgs e)
{
String sql = "select title from up_song ";
SqlDataAdapter adpt = new SqlDataAdapter(sql, cn);
DataSet ds = new DataSet();
adpt.Fill(ds, "title");
if (ds.Tables["title"].Rows.Count > 0)
{
int m = ds.Tables["title"].Rows.IndexOf(ds.Tables["title"].Rows[8]);
int k = ds.Tables["title"].Rows.IndexOf(ds.Tables["title"].Rows[1]);
for (i=m; i >= k ; --i)
{
try
{
hp[i] = new HyperLink();
hp[i].ID = "hp" + i;
hp[i].Text = ds.Tables["title"].Rows[i].ItemArray[0].ToString();
hp[i].NavigateUrl = "Downloadpage.aspx";
hp[i].ForeColor = System.Drawing.Color.White;
Panel1.Controls.Add(hp[i]);
Panel1.Controls.Add(new LiteralControl("<br>"));
HttpCookie coo = new HttpCookie("song");
coo["sogtit"] = ds.Tables["title"].Rows[i].ItemArray[0].ToString();
Response.Cookies.Add(coo);
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
}
String sql1 = "select title from up_song where Song_type='Indian Pop Album'";
SqlDataAdapter adpt1 = new SqlDataAdapter(sql1, cn);
DataSet ds1 = new DataSet();
adpt1.Fill(ds1, "title");
if (ds1.Tables["title"].Rows.Count > 0)
{
String query = "select max(song_id) from up_song;";
SqlDataAdapter adpt2= new SqlDataAdapter(query,cn);
DataSet ds2= new DataSet();
adpt2.Fill(ds2,"max");
//int m = ds.Tables["title"].Rows.IndexOf(ds1.Tables["title"].Rows[query]);
//int k = ds.Tables["title"].Rows.IndexOf(ds.Tables["title"].Rows[1]);
for (i = 0; i <= ds2.Tables["max"].Rows.Count; ++i)
{
try
{
hp[i] = new HyperLink();
hp[i].ID = "hp" + i;
hp[i].Text = ds1.Tables["title"].Rows[i].ItemArray[0].ToString();
hp[i].NavigateUrl = "Downloadpage.aspx";
hp[i].ForeColor = System.Drawing.Color.White;
Panel2.Controls.Add(hp[i]);
Panel2.Controls.Add(new LiteralControl("<br>"));
HttpCookie coo = new HttpCookie("song");
coo["sogtit"] = ds.Tables["title"].Rows[i].ItemArray[0].ToString();
Response.Cookies.Add(coo);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
cn.Close();
select top 6 title from up_song order by song_id desc

Categories

Resources