I am currently developing a C# Windows Form Application.
Now I am trying to use a SQL Command to retrieve information from the database to fill in the information that I need to have in my Application.
A sample query would be “select * from Member”
In the member table there would be variables like name, location, etc etc.
How do I code it in my application such that i can fill up my variables with the information from the database?
My code for the method would be
private Panel createNotificationPanel(String name, String location, String imageExtension, String alertType, String memberid)
{
}
I have already created a member class which includes all the set and get method for all this values
and currently what I have done so far is :
String connectionString = ConfigurationManager.ConnectionStrings["connection2"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("select * from alert);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet dataset = new DataSet();
conn.Open();
da.Fill(dataset, "authenticate");
conn.Close();
int respond = (int)dataset.Tables["authenticate"].Rows[0]["respond"];
if (respond == 1)
{
//to fill in here
}
after retrieving the information I am going to add it to a list as follow
List.Add(new MemberAlert("name", "location", "type", "memberID", "imageExtension"));
so i am wondering how do i replace the information inside with the one in the database
I am not sure of how do I proceed from here. can anyone help me with this?
if you need to create list out of dataset table. you can iterate rows as above and create list items inside the loop and add them to list.