using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
public partial class temp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//string con01 ="Data Source=localhost; Initial Catalog=Northwind;" +
// "user id=sa; password=opensesame";
//string connectionString = WebConfigurationManager.ConnectionStrings["sqlcon01"].ConnectionString;
// SqlConnection con = new SqlConnection(connectionString);
// System.Data.SqlClient.SqlCommand com01=new SqlCommand("select * from accounts",con);
//System.Data.SqlClient.SqlDataAdapter da01= new SqlDataAdapter("select * from accounts",con);
//System.Data.DataSet ds01 =new DataSet();
// da01.Fill(ds01,"accounts");
// gv01.DataSource = ds01.Tables["accounts"];
// gv01.DataBind();
// Create the Connection object.
string connectionString =
WebConfigurationManager.ConnectionStrings["sqlcon01"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
try
{
// Try to open the connection.
con.Open();
lblInfo.Text = "Server Version: " + con.ServerVersion;
lblInfo.Text += "
Connection Is: " + con.State.ToString();
}
catch (Exception err)
{
// Handle an error by displaying the information.
lblInfo.Text = "Error reading the database. " + err.Message;
}
finally
{
// Either way, make sure the connection is properly closed.
// Even if the connection wasn't opened successfully,
// calling Close() won't cause an error.
con.Close();
lblInfo.Text += "
Now Connection Is: " +
con.State.ToString();
}
Getaccounts();
}
public void Getaccounts()
{
string connectionString = WebConfigurationManager.ConnectionStrings["sqlcon01"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("select * from accounts", con);
//cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
// Fill the DataSet.
//try
//{
da.Fill(ds, "accnts");
// return ds.Tables["accnts"];
gv01.DataSource = ds.Tables["accnts"];
gv01.DataBind();
SqlCommand cmd02 = new SqlCommand("select * from accinfo", con);
//cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da02 = new SqlDataAdapter(cmd02);
DataSet ds02 = new DataSet();
// Fill the DataSet.
//try
//{
da02.Fill(ds, "accinf");
// return ds.Tables["accnts"];
// gv01.DataSource = ds.Tables["accnts"];
//gv01.DataBind();
StringBuilder htmlStr = new StringBuilder("");
foreach (DataRow dr in ds.Tables["accinf"].Rows)
{
htmlStr.Append("
");
htmlStr.Append(" htmlStr.Append(dr["username"].ToString()); htmlStr.Append(" "); htmlStr.Append(dr["firstname"].ToString()); htmlStr.Append(" "); htmlStr.Append(dr["lastname"].ToString()); htmlStr.Append(" "); htmlStr.Append(dr["middlename"].ToString()); htmlStr.Append(" "); htmlStr.Append(dr["remarks"].ToString()); htmlStr.Append(", "); htmlStr.Append(" htmlStr.Append(" | ");
");
htmlStr.Append("shit "); htmlStr.Append(" | ");
}
Label1.Text= htmlStr.ToString();
// }
// catch
// {
// throw new ApplicationException("Data error.");
//}
}
protected void Button1_Click(object sender, EventArgs e)
{
string connectionString = WebConfigurationManager.ConnectionStrings["sqlcon01"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);
con.Open();
string sql01 ="INSERT INTO accounts (username,password,type,description) VALUES('" + tb01.Text + "','" + tb02.Text + "','" + tb03.Text + "','" + tb04.Text + "')";
System.Data.SqlClient.SqlCommand com01=new SqlCommand(sql01,con);
com01.ExecuteNonQuery();
Response.Redirect("dfront.aspx");
//System.Data.SqlClient.SqlDataAdapter da01= new SqlDataAdapter(com01);
//System.Data.DataSet ds01 =new DataSet();
//da01.Fill(ds01,"accounts");
// gv02.DataSource = ds01.Tables["accounts"];
//gv02.DataBind();
con.Close();
}
protected void Reset1_Click(object sender, EventArgs e)
{
Label1.Text = "shit";
}
}