0
private void EnterAcNotextBox_TextChanged(object sender, EventArgs e)
        {
            int id;
            if (!int.TryParse(AcNotextBox.Text, out id))
            {
                return;
            }
            string connString = ConfigurationManager.ConnectionStrings["dbx"].ConnectionString;

            string cmdString = "SELECT '#' FROM tblBasicInfo, tblAccData WHERE ID =" + Convert.ToInt32(AcNotextBox.Text);

            //string query = "SELECT * FROM tblAccData WHERE ID =" + Convert.ToInt32(AcNotextBox.Text);

            using (OleDbConnection conn = new OleDbConnection(connString))
            {
                using (OleDbCommand cmd = new OleDbCommand(cmdString, conn))

                {
                    conn.Open();

                    OleDbDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        StudentNametextBox.Text = (reader["SName"].ToString());
                        FatherNametextBox.Text = (reader["FName"].ToString());
                        ClasscomboBox.Text = (reader["ClassofReading"].ToString());
                        TransportFatextBox.Text = (reader["TranFacility"].ToString());
                        RemarkstextBox.Text = (reader["Remarks"].ToString());
                        CelltextBox.Text = (reader["Cell"].ToString());
                        TrantextBox.Text = (reader["TransportChr"].ToString());

                        DuestextBox.Text = (reader["Dues"].ToString());
                        AdmfeetextBox.Text = (reader["Adm"].ToString());
                        ProFeetextBox.Text = (reader["Pro"].ToString());

                    }
                }
            }
3
Contributors
2
Replies
13
Views
3 Months
Discussion Span
Last Post by Shark_1
0

From my opinion your problem should be in construction of sql statement i.e."SELECT '#' FROM tblBasicInfo, tblAccData WHERE ID =" + Convert.ToInt32(AcNotextBox.Text)

Use Inner join clause to join two tables.
You can try it

"SELECT A.ID,A.Name,.....,B.Pro FROM tblBasicInfo A Inner Join tblAccData B On B.ID=A.ID WHERE A.ID =" + Convert.ToInt32(AcNotextBox.Text)

***Use Parameterised queries to prevent sql injection to your database.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.