Posts

Showing posts from 2016

How to get html of web page in string by web page url

Image
           Hi friends sometimes we need a content of web page like text or links and many more things.then we use the html of page by inspect elements.            Now that we do by c# code.this work on both web and window application. First include library of " using System.Net; " Second code for one line. string strhtml = new WebClient().DownloadString("http://facebook.com"); This returns string of all web page html in string. We can manipulate string and get we require content.

How to resolve "Logon Failed" Error in crystal report

Image
Hi friends, Crystal report is a rich tool of reporting and analysis.when you setup in win application.it works good in development side.but when setup in deployment side come this logon fail error. This error come because crystal report set database connection in report data.and when we change database location or change server then crystal report can't connect with database.so this error come to user. for solution this problem need some code for resolve this issue.this call set login detail to crystal report. //create ReportDocument CrystalDecisions.CrystalReports.Engine.ReportDocument cryRpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); //ConnectionInfo ConnectionInfo info = new ConnectionInfo(); //set database server name info.ServerName = Server name; //set database userid info.UserID = userid; //set database password info.Password = password; //set database IntegratedSecurity info.IntegratedSecurity = false; //set report used data...

How to get month days count from date or month and year

Hi all . Window form application need some calculation of date and days,so require no of days in current month or any date of month. So for that we use on c# in build function to get days count. System.DateTime.DaysInMonth(Year(int), Month(int)); This function output number of days in integer. And we need to input year and month number in integer value. If you have date then we get month and year from it. DateTime NowDate = new DateTime(); int iMonth=NowDate.Month; int iYear=NowDate.Year; If you have month name so need to get number of month int iMonth=DateTime.ParseExact("MonthName", "MMMM", CultureInfo.InvariantCulture).Month For this code need to include using System.Globalization; library. Thanks to read this post. comment if any problem in code.

Export datatable data in Excel

Hi to all. Normally we work in database but some time we need reporting or get data in soft copy to send email or for record purpose. So we export data in excel file.hear i show you how to export data from datatable . first get data from database to in datatable which we show in starting session. I genrate one function that help to export in Excel .   public bool DatatabletoExcel(DataTable Dt)         {             bool result = false;             try             {                 //create dialog for create file                 SaveFileDialog sfd = new SaveFileDialog();                 sfd.FileName = "File Name";                 sfd.DefaultExt = "xls";                ...

How to work with comma-separated strings

Hi to all. In this post we introduce with comma separated strings. how we can work with it and manipulate in our work. string language= "C#,Java,Php,python; now we convert it to string array . string[] languageArray= language.Split(','); foreach (string slanguage in languageArray) {     //code what you want     //print slanguage } We can split comma separated string like this.also we can split any character with split function. like language.Split('|'); Thanks for read post. Any problem comment us.

Insert data in AutoNumber DataType (Access Database).

Hi to all. Normally we insert data in table.but when we need some unique identity we use primary key and make  AutoNumber datatype in access database. so when we insert data in database not add column in query of insert. Like table name is Test and columns are Id=>AutoNumber,Name=>Text Query for insert is ="Insert into Test (Name) Values ('TestName')" Hear we not mention Id because Id is AutoNumber. It automatically set last id increment 1.and if we want the inserted id in database after insert query make one code " Select @@Identity "; to execute.         public int InsertData(string sQuary)         {             try             {                 //for get last inserted id                 string sQryIdentity = "Select @@Identity";             ...

Insert date in database by DateTimePicker

Hi to all. If you are new in developing so you have mostly problem to add date in database. so i make code for new beginners. first take one  DateTimePicker name it to Dtdate. Set property Format=Short so we get simple date not in long format. Take one button so on click event we save in database. In Button click event. string Dtdate = Dtdate.Value.ToString("yyyy-MM-dd"); Now the string contain date string in "yyyy-MM-dd" format. on save time make query for date. string sQuary="Insert into testTable (Dtdate) Values (#"+Dtdate +"#)" ; Execute this query. In query I use "#" on start and end. that specify this is date. in database date save always in  "yyyy-MM-dd" format so i convert in this format. Thanks for read this post

Fill List view from database

Image
Hi to all. In this post we make code for populate list view from database. first we take one list view and name them listdata. and set in form with require height and width. listview now make one function FillList() to populate listview.         private void FillList()         {             try             {                 //use dbhelper class to fill datatable from database.                 DbHelper Db = new DbHelper();                 //make query string .                 string sQry = "Select * from Employee";                 //call function for fill datatable.                 DataTable Dt = Db.FillDataTable(sQry);     ...

Populate combo box for month and year in c#

Image
Hi to all. In this post we populate combo box for month and year. First take two combo box one for month and second for year.Name them  CmbMonth and  CmbYear . we create function for fill data in combo box. For month combo box         private void Fill_CmbMonth()         {             try             {                              //clear all data from combobox                 CmbMonth.Items.Clear();                 //add default item                 CmbMonth.Items.Add("Select");                 //fill array from System.Globalization.DateTimeFormatInfo.InvariantInfo                 var ...

Fill datatable from access database

Hi to all. In previous post we show  how to execute query in database. now in this post we see how to get data from database. and fill in  DataTable . for this we create on function in dbhelper class which we use in previous example.         public DataTable FillDataTable(string sQry)         {             try             {                 DataTable Dt = new DataTable();                              //Check db connection                 if (dbConnection.State != ConnectionState.Open)                 {                     dbConnection.Open();                 }         ...

CRUD Operations in win form application with access database

Hi to all, In first post we connect with access database now in this post we make operations in database. First we create one method that help to execute sql query in database. public bool Executquary (string sQuary)         {             try             { //check connection                 if (dbConnection.State != ConnectionState.Open)                 {                     dbConnection.Open();                 } //create command                 OleDbCommand cmd = new OleDbCommand(sQuary);                 cmd.Connection = dbConnection;                 try                 { /...

Create class for Access database connection

Image
Hello to all,      Here we make on class that help to connect application's database by simply call class.          First we create Win form application .like Testapp. create one Access database like Testapp.accdb. after that we open application in visual studio and create one folder that name app_code. in this folder add one class file.and name them dbhelper.cs. public class DbHelper     {         public static OleDbConnection dbConnection;         public DbHelper()         {             dbConnection = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0; Persist Security Info = False; Data Source=c:\\Testapp.accdb");             dbConnection.Open();         } } For this code you need to include some libraries like System.Data.OleDb ; Now time to use this c...