if(!IsPostBack)
{
SqlConnection con = new SqlConnection("Server = Lissadell; database = tmccormack; uid = tmccormack; password = chocolate");
con.Open();
SqlCommand com = new SqlCommand("Select code from STOCK order by code asc" );
com.CommandType = CommandType.Text;
com.Connection= con;
SqlDataReader sdr = com.ExecuteReader();
while(sdr.Read())
{
ListBox1.Items.Add((string)sdr["code"]);
}
sdr.Close();
con.Close();
}
}
private void Display(string sqlQuery)
{
try
{
SqlConnection con = new SqlConnection("Server=Lissadell; database=tmccormack; uid=tmccormack; pwd=chocolate");
con.Open();
SqlCommand com = new SqlCommand();
com.Connection=con;
com.CommandType = CommandType.Text;
com.CommandText = sqlQuery;
SqlDataReader sdr = com.ExecuteReader();
if(sdr.Read())
{
txtCode.Text = sdr[0].ToString();
txtDesc.Text = sdr[1].ToString();
txtPrice.Text = sdr[2].ToString();
txtQty.Text = sdr[3].ToString();
sdr.Close();
con.Close();
}
else
{
Label1.Text= " No records with this value Found";
}
}
catch(Exception e1)
{
Label1.Text=e1.ToString();
}
}
private void butCode_Click(object sender, System.EventArgs e)
{
string sqlst = "SELECT code, description, price, qty FROM Stock"
+" where code ='"+TextBox5.Text+"'";
private void grid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
grid1.EditItemIndex= -1;
Display("Select * from Stock order by code");
}
private void grid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string stCode= e.Item.Cells[0].Text;
TextBox txtDesc = (TextBox)e.Item.Cells[1].Controls[0];
string sdesc = txtDesc.Text;
TextBox txtPrice = (TextBox)e.Item.Cells[2].Controls[0];
string sPrice = txtPrice.Text;
TextBox txtQty = (TextBox)e.Item.Cells[3].Controls[0];
string sQty = txtQty.Text;
Display("Update Stock set description='" +sdesc+"', price = "+sPrice+", qty="+sQty+" where code ='"+stCode+"'");
grid1.EditItemIndex=-1;
Display("Select * from Stock order by code");
}
private void grid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
string stCode= e.Item.Cells[0].Text;
Display("Delete from Stock where code ='"+stCode+"'");
grid1.EditItemIndex=-1;
Display("Select * from Stock order by code");
}
catch(Exception e1)
{
lblErr.Text= e1.ToString();
}
grid1.DataSource = com.ExecuteReader(CommandBehavior.CloseConnection);
grid1.ShowHeader=true;
grid1.ShowFooter=true;
grid1.BorderColor=Color.Black;
grid1.BackColor=Color.Gray;
grid1.AlternatingItemStyle.BackColor=Color.Snow;
grid1.HeaderStyle.BackColor=Color.Red;
grid1.ForeColor=Color.Black;
grid1.Font.Bold=true;
grid1.DataBind();
Display(sqlst);
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
Display("Select * from Stock order by code");
}
private void Update(string stCom)
{
try
{
SqlConnection con = new SqlConnection("server=lissadell; database=tmccormack; uid=tmccormack; pwd=chocolate");
con.Open();
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = stCom;
com.ExecuteNonQuery();
con.Close();
}
catch(Exception e1)
{
lblError.Text = e1.ToString();
}
}
private void Display(string stCom)
{
try {
SqlConnection con = new SqlConnection("server=lissadell; database=tmccormack; uid=tmccormack; pwd=chocolate");
con.Open();
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = stCom;
grid1.DataSource = com.ExecuteReader(CommandBehavior.CloseConnection);
grid1.DataBind();
}
catch(Exception e1)
{
lblError.Text = e1.ToString();
}
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
private void grid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
foreach (TableCell tc in e.Item.Cells)
{
lstBox1.Items.Add(tc.Text);
}
try
{
Session["code"] = e.Item.Cells[1].Text;
Server.Transfer("WebForm2.aspx");
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
private void BtnNew_Click(object sender, System.EventArgs e)
{
DS.Tables[0].Rows.InsertAt(DS.Tables[0].NewRow(),0);
Grid2.EditItemIndex = 0;
Grid2.DataBind();
EditCommandColumn ecc = (EditCommandColumn)Grid2.Columns[5];
ecc.UpdateText = "INSERT";
//INTO stock (code,description,price,qty)VALUES("+txtD.Text+","+txtP.Text+","+txtQ.Text+")";
Grid2.DataBind();
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
XML STUFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!
private void Page_Load(object sender, System.EventArgs e)
{
string sPath = Server.MapPath ("")+"\\mydata.xml";
lblSource.Text=sPath;
ds = new DataSet();
ds.ReadXml(sPath);
dGrid.DataSource=ds;
dGrid.DataBind();
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
In Button update Click - with try and catch's !!!!!!!!!!!!!!!!!!!!!!!!!!
double price;
foreach(DataRow dr in ds.Tables[0].Rows)
{
price = double.Parse(dr[2].ToString());
price += 2.0;
dr[2] = price.ToString();
}
string tpath = Server.MapPath("")+"\\mydata.xml";
ds.WriteXml(tpath);
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Bind grid method
SqlConnection con = new SqlConnection("Server = Lissadell; database = tmccormack; uid=tmccormack; pwd = chocolate");
con.Open();
SqlCommand com = new SqlCommand();
com.Connection= con;
com.CommandType = CommandType.Text;
com.CommandText = "Select * from BigTable Order by studentId";
DataSet ds = new DataSet();
SqlDataAdapter dap = new SqlDataAdapter(com);
dap.Fill(ds,"BigTable");
dgrid.DataSource=ds;
dgrid.DataMember="BigTable";
dgrid.DataBind();
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Parameters!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
private void BindGrid2()
{
try
{
SqlConnection con = new SqlConnection("Server = Lissadell; database = tmccormack; uid=tmccormack; pwd = chocolate");
SqlCommand com = new SqlCommand();
com.Connection= con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "GetNextPageFromBigTable";
com.Parameters.Add(new SqlParameter("@CurrentPage",SqlDbType.Int)).Value= curpage;
com.Parameters.Add(new SqlParameter("@PageSize",SqlDbType.Int)).Value = dgrid.PageSize;
com.Parameters.Add(new SqlParameter("@TotalRecords", SqlDbType.Int)).Direction =ParameterDirection.Output;
con.Open();
dGrid2.DataSource= com.ExecuteReader();
dGrid2.DataBind();
lblCurrent.Text= curpage.ToString();
double totPages=1;
if(!IsPostBack)
{
int totrecs = (int)com.Parameters["@TotalRecords"].Value;
totPages = totrecs / dGrid2.PageSize;
lblLast.Text= (System.Math.Ceiling(totPages)).ToString();
}
else
{
totPages = double.Parse(lblLast.Text);
}
if ( curpage == 1 )
{
butPrevious.Enabled = false;
if ( totPages > 1 )
{
butNext.Enabled = true;
}
else
{
butNext.Enabled = false;
}
}
else
{
if (curpage ==1)
{
butPrevious.Enabled=false;
}
if(curpage==totPages)
{
butNext.Enabled = false;
}
else
{
butNext.Enabled= true;
}
}
}
catch(Exception ee)
{
lblMsg.Text=ee.Message;
}
}
private void dgrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgrid.CurrentPageIndex= e.NewPageIndex;
BindGrid2();
}
private void butFirst_Click(object sender, System.EventArgs e)
{
curpage=1;
BindGrid2();
}
private void butNext_Click(object sender, System.EventArgs e)
{
curpage = Int32.Parse ( lblCurrent.Text ) + 1;
BindGrid2();
}
private void butPrevious_Click(object sender, System.EventArgs e)
{
curpage = Int32.Parse ( lblCurrent.Text ) - 1;
BindGrid2();
}
private void butLast_Click(object sender, System.EventArgs e)
{
curpage = Int32.Parse(lblLast.Text);
BindGrid2();
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
allow paging in the property event
private void dgrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgrid.CurrentPageIndex= e.NewPageIndex;
BindGrid();
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
MONITORING!!
using System.Diagnostics;
foreach ( EventLog ev in EventLog.GetEventLogs())
{
lstLogs.Items.Add(ev.Log);
}
string srcname = "Test_Application";
if (!EventLog.SourceExists(srcname)) // check if the source already exists
{
try
{
EventLog.CreateEventSource(srcname, "Application"); // create new source
lblMsg.Text = "Source " + srcname + " created OK";
}
catch (Exception ex)
{
lblMsg.Text = ex.Message; // display exception message
}
}
else
{
lblMsg.Text = "Source " + srcname + " already exists";
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
[WebService(Namespace="hello")]
[WebMethod]
public string ToUpper(string input)
{
return input.ToLower();
}
add reference to site
ie.itsligo...... obj = new....
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.net Remoting
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
MarshalByRefObject on remote object after class name (: " " )
serverAPP
public static int Main(string [] args)
{
TcpChannel chan = new TcpChannel(8085); ChannelServices.RegisterChannel(chan); RemotingConfiguration.RegisterWellKnownServiceType( Type.GetType(“RemoteTest.HelloServer"), "SayHello", WellKnownObjectMode.SingleCall); System.Console.WriteLine("Hit to exit..."); System.Console.ReadLine();
return 0;
}