Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone I'm just learning C# and currently I'm working with Bank Simulation using SQL database.

Problem: I still can't access or display the specific account number's data into a form.

Need: is when I input account number into text box and click a button a new form will show and display all the information that has this account number.

here is my code:
C#
private void btnOpen_Click(object sender, EventArgs e)
{
    con = new System.Data.SqlServerCe.SqlCeConnection();
    con.ConnectionString = "Data Source=C:\\Users\\Lovette\\Documents\\MyFiles\\ETEEAP\\MODULE-1 C#\\Bankdatabase\\BankAccount.sdf";

    comd = new SqlCeCommand("SELECT * From tbl_bankaccount WHERE AccountNumber='" + tbAccountNum.Text.Trim() + "'", con);
    con.Open();

    reader = comd.ExecuteReader();

    clientRecordForm clientRecords = new clientRecordForm(this);

    while (reader.Read())
    {
        tbAccountNumPR.Text = reader.GetValue(0).ToString();
        tbFirstName.Text = reader.GetValue(1).ToString();
        tbMiddleName.Text = reader.GetValue(2).ToString();
        tbLastName.Text = reader.GetValue(3).ToString();
        tbEmployer.Text = reader.GetValue(4).ToString();
        tbBusinessAdd.Text = reader.GetValue(5).ToString();
        tbHomeAdd.Text = reader.GetValue(6).ToString();
        tbContactNum.Text = reader.GetValue(7).ToString();
        tbMoney.Text = reader.GetValue(8).ToString();
        clientRecords.ShowDialog();
    }
    con.Close();
Posted
Updated 10-Sep-13 0:25am
v4
Comments
[no name] 10-Sep-13 5:52am    
Just like you are doing? Your "problem" statement is not a problem at all. You have to tell us what the problem is.
Lovette 10-Sep-13 6:08am    
Oh my apology for that, problem here is I still can't see the specific data that I wanted to access for the specific Account Number.

All I need is when I input account number in the textbox called tbAccountNumber and a button called btnOpen a new form (clientformofdata) will show and display all the information that has this account number.
[no name] 10-Sep-13 6:25am    
Okay so how exactly is that a problem? You are creating the form, but not doing anything with it, and then showing it. Where do you think that your clientRecordForm is getting its data from?
Lovette 10-Sep-13 6:39am    
I'm getting the data on the Sql database called "tb_bankaccount".
I have SQL database and has 9 columns(AccountNumber, Firstname,middlename, lastname, employer, businessaddress, homeaddress, contactnumber and moneyinBank) and I have 5 data on it..
[no name] 10-Sep-13 7:05am    
Yes I see that. You are not understanding me, I suppose. You are creating a form but you are not doing anything with your data to show it on the form.... So, again, where is it that you think that the form you are creating, clientRecordForm, is getting its data from to show?

design ur first windoe form with a txtbx and btn tp enter Account No.
On btn_click event write the code to call second form which will open now.

form2 obj = new form2();
obj.AccountNo = txtbx.text; // here AccountNo is a publicly defined string variable in form2
obj.show();

now write your query to retrieve all information based on that AccountNo
and show them in different controls.

Instruction:- Better to use dataset than dataReader.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900