Thursday 9 October 2014

C# Step by Step How to dynamically get values from textboxes into gridview



First Step Open Visual studio 

Click on New Project


Now Menu visible Select option Visual C# just like in Picture below

now  select windows form from visual C# windows and name project and save it
now project will be loaded and open the project to design and code
now their is form visible you can now start working


now you see label in toolbox where it can be dragged to create identification of something on interface to use it

now we have dragged
now to change the name of label1 to ID so we write click of mouse and go to its properties which will be visible on write side to change the text name just like below



Another label drag and dropped and change the text name to Name


Now we need textBoxes to get values from user

To identify user to use it we have to change its accessability name value to use in code by going to its properties




Now its accessable for id values now applying same above procedure we have to show textbox for name in change accessibility name is txtName

now to save the data we have to use button on interace where user click and these values in boxes will be stored by drag button from toolbox and drop on form just like that below and change textname from button to Save by using properties

 changing accessibility name of the button to accessable in code





Now after that we need some visible excel like sheet view to visible all the records on button click to user in less time so for show data we use gridview and then drag from toolbox and drop it on form
just like below


now we do code by double click on interface where save button is displaying click on it you will se code view where you can do code



after coding with no error debug and result will be displayed you give input and result dropped and showed in gridview just like that



make sure your project name is same at that line else you will get error to run code


write code as below with different textboxes are used on interface like txtID and txtName dont confuse below is mine written code with different names so dont write as exact just go to your button , textbox property and copy accessibility name use them in code you will avoid errors

Hope you will like this

Code


Form2.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyProjectToGetGridDynamically
{
    public partial class Form2 : Form
    {
        DataTable dt;
        DataRow dr;
        public Form2()
        {
            InitializeComponent();
            dt = new DataTable();
            dt.Columns.Add("id");
            dt.Columns.Add("name");

        }

        private void button1_Click(object sender, EventArgs e)
        {
            dr = dt.NewRow();
            dr[0] = textId.Text;
            dr[1] = textName.Text;
            dt.Rows.Add(dr);
            dataGridView1.DataSource = dt;
        }
    }
}

Monday 6 October 2014

How to use Crystal Report in visual studio 2010

How to download and run crystal reports in C#

To work with crystal report please do following steps

ü  “Please make sure that your visual studio professional edition not enterprise edition or express edition”
ü  Visual studio lacks of it Download latest crystal report extension pack from the sap website.
ü  After the complete installation restart your computer of 10 to 20 minutes wait.
ü  Then Run visual studio
ü  Create new project add crystal report from reporting and on form where to show report you can drag and drop the crystal report from tool box if invisible tool then go to project property and change targeted frame work from .Net frame work4 client to “.Net frame4” build project.

ü  Beware Most Important Steps else you will fail to do coding of crystal report You received head ache error that folder dotnet or dotnet1 not found crdb_adoplus.dll in this location

“C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet\crdb_adoplus.dll”

Go to this location till

“C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\”

Create new folder of “dotnet” which is required then copy the file from folder “C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86” and paste it in the “C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet

Now you got no error :D :D




ü  Modify app config file such that replace the startup with this code
<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    <requiredRuntime version="v4.0.20506" />
  </startup>

ü  Add headers of following in form1.cs code

   using CrystalDecisions.CrystalReports.Engine;
                   using CrystalDecisions.Shared;

ü Add reference as well
CrystalDecisions.Windows.Forms
ü Now your project is completely ready to execute :D :D
Now run your project crystal report perfectly works

Screen shot




Now you are done……!


Good Luck