Skip to main content

Posts

Showing posts from September, 2009

Configure ASP.NET Membership Provider and Role Provider to Use own SQL Server Database

First create a data base using SQL Server. (You can use Visual Studio to create your database) Type your new database name and press ok to continue. Then it will prompt dialog for creating a new database. Then press ok , Now you created a database in your SQL Server. After that go to Visual Studio Command prompt Program Files—> Visual Studio 2008 command prompt and type aspnet_regsql.exe   or C:\Windows\Microsoft.NET\Framework\v2.oxx and run Aspnet_regsql.exe. This command will launch wizard which can use to generate relevant database structure to selected database. Now we have to configure the web.config < connectionStrings > < add name = " ConnectionString " connectionString = " Data Source=TestDB;Initial Catalog=Login;User ID=sa;Password=sapassword " /> </ connectionStrings >   < system.web > < roleManager enabled = " true " defaultProvider = " SqlRoleProvider " > <...

Hide and Show Crystal Report’s Sub Report when we need

Refer to my previous post assume you want to display the sub report only data is available. therefore you can check the data for row availability and if rows are exists you can  display the report. In my example we are placed our sub report in section 4 in main report. thus we can use following code to display the sub report only data is available. if (dts.Rows.Count > 0) { Ci.Subreports[ "SubBalance" ].SetDataSource(( DataTable )dts); } else { Ci.ReportDefinition.Sections[3].SectionFormat.EnableSuppress = true ; }

How to Create a Crystal Report Sub Report in C#.NET

First you need to create the main report.  (Read .. How to Create a Crystal Report using Data sets in C#.NET) Then right click the area which you want to insert a sub report. In my example I’m going to create a sub report for displaying InvoiceNumber , Balance (refer to my previous post) . Then place the report and design the sub report as we did in the main report. Finally right click the sub report and go to Format Object and Give the Object name as SubBalance .  also give the report name as SubBalance when the time of creating the report. Now your main report looks like .. Now you need to load data to the sub report as well as main report when we press the select button using data adapters. (refer Previous post ) private void btnView_Click( object sender, EventArgs e) { SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder (); cb.UserID = "sa" ; cb.Password = "sa123" ; cb.InitialCatalog = "CustomerInfo" ; // Create S...

How to Create a Crystal Report using Data sets in C#.NET

Assume that you already SQL server database created and table also. Following illustrate our table structure and data. CustomerName InvoiceNum TotalAmount Paid Balance Amal 10001S 1000.00 900.00 100.00 Amal 10002S 2500.00 2000.00 500.00 Amal 10003S 1800.00 1500.00 300.00 Amal 10004S 2500.00 2000.00 500.00 Nimal 10005S 3000.00 3000.00 0.00 Nimal 10006S 1000.00 1000.00 0.00 Nimal 10007S 1500.00 1500.00 0.00 First you need to have a data connection created. (Read ..How to create a Data Connection to SQL Server using C#.net Wizard)   Then you need to have a Data set created. (Read .. How to Create a DataSet, DataTables, Table Adapter Using C#.NET Wizard)   In here I’m going to create a report with main data by customer name (CustomerName, InvoiceNum , TotalAmount) therefore i need a data table with relevant fields. To add a Crystal Report go to Project –> Add new items –> Reporting –> CrystalReport .   Than give a...

Select Record using Data Grid,Dataset and Table Adapters in C#.Net

First of all you need to have a Data Connection. (Read.. How to create a Data Connection to SQL Server using C#.net Wizard ) Then you need to have data set and table adapters configured (Read.. How to Create a Dataset, Data Tables, Table Adapter Using C#.NET Wizard)   Then add a data grid ( dtgrid ) to your windows form.  And use following code. When we not saved our connection we need to give connection settings to the table adapter when ever it wants to connect to the data base. private void btnSelect_Click( object sender, EventArgs e) { // using System.Data.SqlClient; import this namespace SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder (); cb.UserID = "sa" ; cb.Password = "sa123" ; cb.InitialCatalog = "CustomerInfo" ; // Create SQL Connection by giving SQL Connection String SqlConnection sc = new SqlConnection (cb.ConnectionString); CusDataSetTableAdapters. CusMainTableAdapter Ta = ...

How to Create a DataSet, DataTables, Table Adapter Using C#.NET Wizard

To create a DataSet First you need to add a data connection to visual studio (Read…).   Assume we are having a table called CusTransactions and having columns CustomerName , InvoiceNum, TotalAmount , Paid , Balance. In my scenario I want to add a Data table to my data set including CustomerName , InvoiceNum and TotalAmount . therefore  first we want to add a dataset. Thus go to Project –> Add new item –> DataSet. And named it as CusDataSet. When you add the data set visual studio shows DataSet Designer. This is the space you can configure your data adapters  and  data tables. ( To add data adapters you can straightway drag and drop tables from your data connection also.) To add a data adapter right click the dataset  designer window and goto Add—> TableAdapter . Then the coming window select the relevant data connection. (You can also create new data connection here)       After the selecting the connection click next to proce...

How to create a Data Connection to SQL Server using C#.net Wizard

For this first  go to server explorer and right click it. then go to Add connection. Then a screen will  come. In that you can enter the server name  and login credentials (username password or windows authentication). Then select the relevant database and use Test Connection to verify the connection. (Windows Authentication takes your windows credentials to log in to SQL Server, If you cant find the Server name open the SQL Server Management Studio and go to server properties.) Read.. (How to Create a DataSet, DataTables, Table Adapter Using C#.NET Wizard)

Microsoft Expression Encoder 3

Encode a wide array of video file formats, stream live from webcams and camcorders or screen capture your PC. Make simple edits to video files and enhance your media with overlays and advertising. Choose encoding settings, choose from a range of player templates and publish rich media experiences with Microsoft Silverlight. Read more…

It’s amazing , Microsoft Expression Web 3

Deliver visually compelling, standards-compliant Web experiences with Expression Web 3 Whether you're an expert or just getting started, building standards-based Web sites is faster and easier with Microsoft Expression Web 3.       Top Features Professional Code Editor Professional Design Surface Visual Diagnostics Broad support for Industry-Standard Technologies Broad support for Industry-Standard Technologies        and many more….

It’s cool, Microsoft Expression Design 3

Microsoft Expression Design 3 creates graphics for use in your design projects . Microsoft Expression Design 3 is the perfect companion to Expression Blend or Expression Web. Leverage existing artwork, or use intuitive drawing tools to quickly build sophisticated vector assets. Seamlessly transfer them to your Expression Blend or Expression Web projects knowing that their fidelity will be maintained throughout the entire designer-developer workflow. Top Features Create Graphics Powerful Tools Editable Effects Read More …

Blog Writing Software

I have tried many blog writers but ultimately Windows Live Writer suits my preference.  its very amazing product with marvelous features. This includes WYSIWYG Editing Photo Editing Plugging Support all most all blog platforms

Querying XML using LINQ to XML in C#

< Customers > < Customer id ="1" orderdate ="4/1/1968" > Paul Koch </ Customer > < Customer id ="2" orderdate ="7/5/1988" > Bob Kelly </ Customer > < Customer id ="3" orderdate ="3/24/1990" > Joe Healy </ Customer > </ Customers > Assume this is the XML file you want to search and it is stores in C:\ drive. XDocument myDoc = XDocument .Load( @"C:\sample.xml" ); Ex –1 get the customer who’s having id 2 Method 1 you can use var type variable and through iteration you can get the result. this method is good when you have more than one record. var q = from c in myDoc.Descendants( "Customer" ) where ( int )c.Attribute( "id" ) == 2 select c; Receiving values by iterating through foreach loop.  foreach ( XElement item in q) { String id =item.Attribute( "id" ).Value; String orderdt = item.Attribute( "orderdate"...

Creating and saving XML using LINQ to XML in C#

XML generation is much easier now in C#. You can use System.Xml.Linq namespace to create XML content much faster and easy. lets look at the following XML. < Customers > < Customer id ="1" orderdate ="4/1/1968" > Paul Koch </ Customer > < Customer id ="2" orderdate ="7/5/1988" > Bob Kelly </ Customer > < Customer id ="3" orderdate ="3/24/1990" > Joe Healy </ Customer > </ Customers > Create XML using Linq to XML Following describes how to create the above xml using xElements. XElement xml = new XElement ( "Customers" ); XElement Customer = new XElement ( "Customer" ); Customer.Add( new XAttribute ( "id" ,1)); Customer.Add( new XAttribute ( "orderdate" , "4/1/1968" )); Customer.Value = "Paul Koch" ; xml.Add(Customer); Customer = new XElement ( "Customer" ); Customer.Add( new XAttribute ( "id...

Change APN Setting programmatically in Blackberry

As shown bellow you want to set APN and Username (optional),Password (optional) in your connection programmatically, if you are not set it in the device. This also caused to Tunnel Failed error. public String HttpGET(String Url) { String AppendURL = ";deviceside=true ;apn=internet.com" ; AppendURL += ";tunnelauthusername=user165;tunnelauthpassword=user165password" ; try { HttpConnection httpConnection = (HttpConnection) Connector.open(Url+AppendURL); httpConnection.setRequestMethod(HttpConnection.GET); InputStream inputStream = httpConnection.openInputStream(); StringBuffer sb = new StringBuffer(); int C; while ( -1 != (C = inputStream.read())) { sb.append(( char )C); }   return sb.toString(); } catch (Exception e) { return "" ; } }

Change the MDI child form’s background color when MDI parent clicks

When you create a form as a MDI child , sometimes you want to access the form object to do some modification from MDI parent. Using following mechanism you can change any associate property of the form. here is a example of changing MDI child’s form background color when MDI parent menu clicks. private void MDIToolStripMenuItem_Click( object sender, EventArgs e) { Control[] CC = this .Controls.Find( "Form1" , true ); foreach (var item in CC) { if (item.GetType().Name== "Form1" ) { Form1 F = (Form1)item; F.BackColor = Color.Aqua; } } }

How to add Button,Checkbox, Radio Button ,any Control to Context Menu in C#

Context Menu is a menu that pops when we click on a control. We can add any windows controls to this context menu using ToolStripControlHost . There are mainly two ways of doing that. we can either extend the ToolStripControlHost to our class or give the control as a constructor. Following describe the second method. Say if you have a button called MainButton and context menu should come  when we click that button. and drag and drop contextMenuStrip from the toolbox. private void MainButton_Click( object sender, EventArgs e) { // Adding a button to Menu Button B = new Button (); B.Text = "My Button" ; // This will bind the event for the button B.Click += new EventHandler (B_Click); ToolStripControlHost Ch = new ToolStripControlHost (B); // Adding a Month Calender MonthCalendar Mc = new MonthCalendar (); ToolStripControlHost Ch1 = new ToolStripControlHost (Mc); //Adding a TextBox TextBox Tb = new TextBox (); Tb.Text =...

How to change the windows form shape in C#

you can change the windows form shape what ever you want. Cool ah..  Lets try to do this. Add new form to your project. (set FormBorderStyle   to None) Use following code for form load private void Form1_Load( object sender, EventArgs e) { GraphicsPath g = new GraphicsPath (); //using System.Drawing.Drawing2D; g.AddEllipse(0, 0, 200, 200); Region r = new Region (g); this .Region = r; }

How to do implement override in C#

class SuperClass { public virtual void MyMethod() { // Code Here } }   class SubClassA : SuperClass { public override void MyMethod() { // Code Here } }   class SubClassB : SubClassA { public override void MyMethod() { // Code Here } } Override is method of implementing polymorphism. Though three classes have same method they will show a unique behavior. as an example, SuperClass A = new SuperClass (); A.MyMethod(); // This will execute code defined in SuperClass A = new SubClassA (); A.MyMethod(); // This will execute code defined in SubClassA Read More

Retrieving Data from SQLServer using Data Set in C#

Assume that you have SQLServer named as “ My-PC ” Database Named as “ TestDB ” UserID for SQL server as “ Melick ” Password for SQL server as “ PassMelick” String ConStr= "" ; ConStr= "Data Source=My-PC;Initial Catalog=TestDB;Persist Security Info=True;"+ "User ID=Melick;Password=PassMelick"; SqlConnection sc = new SqlConnection(ConStr);   SqlCommand scmd = new SqlCommand(); scmd.CommandText = "SELECT * From Table1" ; scmd.CommandType = CommandType.Text; scmd.Connection = sc;   DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(scmd); da.Fill(ds);   string Name= "" ; int Age=0;   foreach (DataRow dtrow in ds.Tables[ "Table1" ].Rows) { Name=dtrow[ "Name" ].ToString(); Age=( int )dtrow[ "Age" ]; } In here manually writing a connection string is difficult. therefore I always prefer to use SqlConnectionStringBuilder Class to generate the Connection String. SqlConnectionSt...