Um. There's a lot of odd code there.
Look at your FillBankName method: why are you doing anything with the dictionary Dctbank, when you don't use it for anything afterwards, and throw it away when the method ends?
I'd suggest that you step back and think about what you want to use to pass data around: Dictionary or DataTable, and write functions which return the appropriate type.
I'd also suggest that you start using Dispose for SQL components: they are scarce resources and should be enclosed in a
using
block. So the DataTable version would be:
public DataTable FillBankName()
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT bank_Id,bank_Name FROM bankdetails", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dt);
}
}
}
return dt;
}
Multi-tier organisation is about separation of concerns: the DB tier knows about the DB only, and the presentation tier knows how to interface with the user and translate that into stuff the data tier can understand. Adding what is effectively presentation code into your data code (such as your "select", "select" row) isn't a good idea, as it forced the data layer to "know" what is happening. I'd stick with DataTable (or better, a collection of a defined class specific to the data you transfer) instead of going with the Dictionary as part of the interface.