Click here to Skip to main content
15,905,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created table, but How can i display database table in Windows Form ?

C#
SqlConnection sqlconn = new SqlConnection("Data Source=AAN-PC;Initial Catalog=friday;Integrated Security=True");
                        SqlDataAdapter sa = new SqlDataAdapter();

                        string query = "insert into Table_1(SensorID,SensorValue,Time) values(@AB, @SV, @TM)";
                        sa.InsertCommand = new SqlCommand(query, sqlconn);

                        sa.InsertCommand.Parameters.AddWithValue("@AB", id);
                        sa.InsertCommand.Parameters.AddWithValue("@SV", hexValue);
                        sa.InsertCommand.Parameters.AddWithValue("@TM", DateTime.Now.ToString("HH:mm:ss"));
Posted
Updated 17-Jan-13 19:13pm
v2
Comments
Sumit_Kumar_Sinha 18-Jan-13 0:57am    
Hey...........You want to fetch the data from database and Display in Winform........or You want to insert winform data in database..............because above code you wrote for data insertation...
ontheline89 18-Jan-13 0:59am    
i need to fetch data and display it in winforms. But i am getting how to display it. Display need to be updated automatically.
Sumit_Kumar_Sinha 18-Jan-13 1:02am    
actually i am not working on winform...............if u need code for web form then i will provide you................you can make changes according to your requirement
ontheline89 18-Jan-13 1:03am    
thank you , i will try to make changes in your web form code.
Jephunneh Malazarte 18-Jan-13 1:03am    
so your saying you want to fetch all database table and you don't know how? if that is yes then try:

select * from information_schema.tables

1 solution

 
Share this answer
 
v2
Comments
ontheline89 18-Jan-13 1:25am    
Data grid is displaying data from database but how can i automatically update a datagrid as new data goes to database.
[no name] 18-Jan-13 1:32am    
Use the following code to refresh your grid.

Add public Refresh method in FormA.

public void RefreshDataGrid()
{
//Do refresh
}

Parse the instance of FormA to FormB when constructing FormB. You have to create FormB contructor to take FormA instance.

private FormA myFormA;
public FormB(FormA formA)
{
myFormA = formA;
}

Now you can call FormA.ResfreshGrid() method from FormB.

myFormA.RefreshGrid();

Thanks
ontheline89 18-Jan-13 1:44am    
ok thank you so much.
I am trying it now.
[no name] 18-Jan-13 1:51am    
Sure dear... Any issues plz do add a comment...
ontheline89 18-Jan-13 1:55am    
My form 2 is not opening.
The idea which i get from you that, making form 2 and placing a button there, when a user press button it will update datagrid in form 1.

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