Salve, leggendo varie guide di msdn online, volevo creare una classe per gestire il database access 2003.
Per adesso ho fatto cosi:
e per richiamare la classe cosi: database db = new database();codice:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.OleDb; namespace test { class database { public void InsertRow(string connectionString, string insertSQL) { using (OleDbConnection connection = new OleDbConnection(connectionString)) { // The insertSQL string contains a SQL statement that // inserts a new row in the source table. OleDbCommand command = new OleDbCommand(insertSQL); // Set the Connection to the new OleDbConnection. command.Connection = connection; // Open the connection and execute the insert command. connection.Open(); command.ExecuteNonQuery(); // The connection is automatically closed when the // code exits the using block. } } public static void ReadData(string connectionString, string queryString) { using (OleDbConnection connection = new OleDbConnection(connectionString)) { OleDbCommand command = new OleDbCommand(queryString, connection); connection.Open(); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine(reader[0].ToString()); } reader.Close(); } } } }
Per fare una insertRow.
Ho usato cosi:
Ora io non so come fare per ReadData, che mi popolasse i textbox , invece che mi va scrivere in console (dos), mi sapete dire come fare?.codice:private void button1_Click(object sender, EventArgs e) { try { string _SQL = "INSERT INTO Prodotti (NominativoProdotto,"; _SQL = _SQL + "Prezzo,"; _SQL = _SQL + "Data)VALUES('" + txtNominativoProdotto.Text + "',"; _SQL = _SQL + "'" + txtPrezzo.Text + "',"; _SQL = _SQL + "'" + txtData.Text + "')"; db.InsertRow(connectionstring, _SQL); } catch (Exception ex) { MessageBox.Show("" + ex.ToString() + ""); } }
Prima di tutto , non sono a scuola perchè io l'ho finita da 5 anni fà ed altri settori,
ma mi voglio divertire ad creare programmi in c#.
Mi potete darmi una mano?.
grazie.

Rispondi quotando
