Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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???

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...