Displaying Database Records Into Label Control



In this video tutorial we will learn how to retrieve database single  record by using windows from  application. and display record into Label Control. To continue with this session please watch previous video. 


Please share if you think these video are useful .Late video we will learn how to consume WCF ,WCF(REST) service into Angular JS Application, Windows Form Application, Console Application etc .  In this session we are trying to learn some basic knowledge about insert , update and delete operation . 
Here is what we i want do . First we need to create database in SQL server .Here is the SQL Script to Create the Database  table and insert some data  but we will be doing it by using windows form application .I already created the required table and inserted some sample data.  

CREATE TABLE [dbo].[ACCOUNT](
[Account_Number] [int] IDENTITY(1,1) NOT NULL,
[Tittle] [nvarchar](50) NULL,
[First_Name] [nvarchar](50) NULL,
[Last_Name] [nvarchar](50) NULL,
[Occupation] [nvarchar](50) NULL,
[DOB] [nvarchar](50) NULL,
[Mobile] [nvarchar](50) NULL,
[Home_No] [nvarchar](50) NULL,
[Street_Name] [nvarchar](50) NULL,
[Country] [nvarchar](50) NULL,
[Post_Code] [nvarchar](50) NULL,
[Gender] [nvarchar](50) NULL,
[Anual_Salary] [money] NULL,
[statementamount] [money] NULL,
[Email] [nvarchar](50) NULL,
[Nationality] [nvarchar](50) NULL,
[FileName] [nvarchar](500) NULL,
[FileData] [varbinary](max) NULL,
[Type_Of_Account] [nvarchar](50) NULL,
[Branch_Name] [nvarchar](50) NULL,
[Sort_Code] [nvarchar](50) NULL,
[Over_Draft] [money] NULL,
[physicallyChallenged] [nvarchar](50) NULL,

)

we want to retrieve account record by providing Account Number. 


Here is How we want to design windows form application .




Just double click the button to generate the button event .Copy and paste following codes .
  private void button1_Click(object sender, EventArgs e)
        {
 SqlConnection cn = new SqlConnection(@"Data Source=.;Initial Catalog=Login;Integrated Security=True");
            string sql = "select * from ACCOUNT where Account_Number='" + textBox1.Text + "'";

            SqlCommand cmd = new SqlCommand(sql, cn);
            cn.Open();
            using (SqlDataReader dr = cmd.ExecuteReader())
            {
                if (dr.Read())
                {
                    label9.Text = dr["Account_Number"].ToString();
                    label10.Text = dr["First_Name"].ToString();
                    label12.Text = dr["Home_No"].ToString();
                    label16.Text = dr["Street_Name"].ToString();
                    label17.Text = dr["Post_Code"].ToString();
                    label18.Text = dr["Mobile"].ToString();
                    label19.Text = dr["Over_Draft"].ToString();
                    label30.Text = dr["Type_Of_Account"].ToString();
                    label31.Text = dr["statementamount"].ToString();
                    label32.Text = dr["Occupation"].ToString();
                    label33.Text = dr["DOB"].ToString();
                    label34.Text = dr["Gender"].ToString();
                    label35.Text = dr["Nationality"].ToString();
                    label36.Text = dr["Sort_Code"].ToString();
                }
            }
        }
     

If done everything correctly you will be able to retrieve the record and will display inside the Label control  . 

2 comments:

  1. hey there!! will you send me this whole project on email jahanvipuri291200@gmail.com... i got same project.... please sir share whole project with source code and database i will be thankful to you sir!!!! waiting for your reply

    ReplyDelete
    Replies
    1. All the code is provided into the blog just code and paste it into your visual studio

      Delete