Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   refresh database automaticaly (not datasource) (http://www.go4expert.com/forums/refresh-database-automaticaly-datasource-t26984/)

achillf 21Oct2011 05:02

refresh database automaticaly (not datasource)
 
Hello i make 2 function which with first Datareader i read from the database and from the another i edit the database's tables. here is the functions:

Code:

public string DatabaseReader(string select, string read)
{
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\Users\\Achill\\Documents\\Visual Studio 2010\\Projects\\WindowsFormsApplication2\\WindowsFormsApplication2\\bin\\Debug\\basi.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand command = conn.CreateCommand();
command.CommandText = select;
bool syndesh = true;
try
{
conn.Open();
}
catch
{
showError("Αδύνατη σύνδεση με τη βάση δεδομένων");
syndesh = false;
}
if (syndesh)
{
SqlDataReader reader = command.ExecuteReader();
while (reader.Read()) return reader[read].ToString();
conn.Close();

}
return "noData";
}







public void DatabaseChange(string write)
{
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\Users\\Achill\\Documents\\Visual Studio 2010\\Projects\\WindowsFormsApplication2\\WindowsFormsApplication2\\basi.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand command = conn.CreateCommand();
command.CommandText = write;
bool syndesh = true;
try
{
conn.Open();
}
catch
{
showError("Αδύνατη σύνδεση με τη βάση δεδομένων");
syndesh = false;
}
if (syndesh)
{
command.ExecuteNonQuery();
}
}



I want when i debug the program when i edit or add something from any table i want to refresh the database automaticaly and its not nesacary to close the program and open again to read it.

here is an example to understand what i mean:

DatabaseChange("insert into table (column1,column2) values ('data1','data2')";
label1.Text = DatabaseReader("select data1 from table where column2='data2'","data1");

and in the label1's text goes noData.

How is possible to refresh and go the new data who i insert?
i dont want datasource or datagridview if this is possible.
if is important then tell me the way to fix it. thanks.


All times are GMT +5.5. The time now is 00:02.