bluejaguar456 Posted October 15, 2006 Posted October 15, 2006 Hello everyone, does anyone know if there is a way of copying from a database to a variable without putting it in a dataset to view it on the form i dont want the user to view it on the form. i know that in vb6 you can do somethin like this: variable = adodatabase.recordset.fields("xxxx") with that code it puts it straight onto the database and nowhere else. does anyone know if there is a way??? Quote
grip003 Posted October 23, 2006 Posted October 23, 2006 What do you mean by not showing it on the form? The only way I know how to retrieve information from a database is through the DataAdapter. You can load the information into a DataSet or a DataTable if you wanted to. I use MySQL as my database and I simply wrote a class for doing all my database retrievals. Here is the code I use to get a DataTable from a select sql statement: public DataTable SelectSQL_DT(string selectStr, string dtName) { try { MySqlConnection dbConnection = new MySqlConnection(connectionString); dbConnection.Open(); MySqlDataAdapter adapter = new MySqlDataAdapter(selectStr, dbConnection); DataTable my_table = new DataTable(dtName); adapter.Fill(my_table); // Dispose of the adapter, it is no longer needed adapter.Dispose(); dbConnection.Close(); return my_table; } catch (MySqlException e) { throw new Exception("SQL statement execution " + "error!!\n\n" + "Trying statement:\n " + selectStr + "\n\n" + e.Message); } } Hope that helps. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.