July 17, 2008
· Filed under Axp.net, C#, Today · Tagged asp.net, C#, Data Access, web development
hey guyz finally we have to learn how to update our tables in database so only for you guys here is my sample code
string giftId = GridView1.SelectedRow.Cells[0].Text.ToString(); //getting an id
SqlDataSource myDbSource = new SqlDataSource();
myDbSource.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
//myDbSource.InsertCommand = “update gifts set giftActivate=1 where giftId=” + Entrydate + “)”;
myDbSource.UpdateCommand = “update gifts set giftActivate=’1′ where giftId=” + giftId;
myDbSource.ProviderName = “System.Data.SqlClient”;
myDbSource.Update();
Well this code set giftActive flag to 1 for all the rows matched with giftid value.
July 17, 2008
· Filed under Axp.net, C#, Devlopment, Today · Tagged asp.net, C#, Data Access, web development
Hey guyz today i will show you how to fire delete query by using our beloved control sqldatasource.
Here is the code
SqlDataSource myDbSource22 = new SqlDataSource();
myDbSource22.ConnectionString = ConfigurationManager.ConnectionStrings["lalConnectionString"].ConnectionString;
myDbSource22.ProviderName = “System.Data.SqlClient”;
myDbSource22.DeleteCommand = “delete from ProductsGroups where pid = ” + productId;
myDbSource22.Delete();
All it does it deletes all the rows for a given productID from table productgroups. Simple right
July 16, 2008
· Filed under Axp.net, C#, Devlopment · Tagged asp.net, C#, web development
hi guyz
Sorry for writing after such a long time i guess i am very busy now a days so for a project i needed to read my smtp email settings defined in my web.config file so after some efforts i am able to read these settings direct from my system .net section.
System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
System.Net.Configuration.MailSettingsSectionGroup settings = (System.Net.Configuration.MailSettingsSectionGroup) config.GetSectionGroup(“system.net/mailSettings”);
Response.Write(“<br>Username=”+settings.Smtp.Network.UserName);
Response.Write(“<br>Password=” + settings.Smtp.Network.Password);
Response.Write(“<br>host=” + settings.Smtp.Network.Host);
Response.Write(“<br>port=” + settings.Smtp.Network.Port);
Response.Write(“<br>from=” + settings.Smtp.From);
November 6, 2007
· Filed under Axp.net, C#, Devlopment · Tagged asp.net, C#, web development
If you want to know only the directory name not the full path of the page that is currently displaying you can use this code
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Directory.Name.ToString();
Response.Write(“<br><br>Directory name===” + sRet + “<br><br>”);
Happy Coding
Najam Sikander Awan
November 6, 2007
· Filed under Axp.net, C#, Devlopment · Tagged asp.net, C#, web development
If you want to display the filename or page name of the current displaying page just use these two lines and it will show only the filename like default.aspx, najam.aspx or indexas.aspx no matter it these pages are located deep into your site structure.
string pagename = System.IO.Path.GetFileName(Request.ServerVariables["SCRIPT_NAME"]); Response.Write(pagename);
Enjoy coding
Najam Sikander Awan