I make a windows form application with 4 text fields.
And I connect the database to it. When I run the program I want to display the data in text fields but it displays nothing as shown below:

and then I always got the error "NullReferenceE xception was unhandled". I don't know if why this happen. My codes is :
This is the screen show when I run the program, the error is in the method "NavigateRecord s". How can I solve this? Thanks in advance!
And I connect the database to it. When I run the program I want to display the data in text fields but it displays nothing as shown below:

and then I always got the error "NullReferenceE xception was unhandled". I don't know if why this happen. My codes is :
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EmployeesDatabase
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DatabaseConnection objConnect;
string conString;
DataSet ds;
DataRow dRow;
int MaxRows;
int inc = 0;
private void Form1_Load(object sender, EventArgs e)
{
try
{
objConnect = new DatabaseConnection();
conString = Properties.Settings.Default.EmployeesConnectionString;
objConnect.connection_string = conString;
objConnect.Sql = Properties.Settings.Default.SQL;
ds = objConnect.GetConnection;
MaxRows = ds.Tables[0].Rows.Count;
NavigateRecords();
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
private void NavigateRecords()
{
dRow = ds.Tables[0].Rows[t];
txtFirstName.Text = dRow.ItemArray.GetValue(1).ToString();
txtSurname.Text = dRow.ItemArray.GetValue(2).ToString();
txtJobTitle.Text = dRow.ItemArray.GetValue(3).ToString();
txtDepartment.Text = dRow.ItemArray.GetValue(4).ToString();
}
}
}
Comment