Database to variable

bluejaguar456

Well-known member
Joined
Aug 22, 2006
Messages
47
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:

Code:
 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???
 
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:
Code:
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.
 
Back
Top