Friday, August 10, 2007

Using the DataAdapter

string connectionString = "Data Source=(local);Initial Catalog=test;Integrated Security=SSPI;";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();

DataSet ds = new DataSet();

SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = new SqlCommand();
dataAdapter.SelectCommand.Connection = conn;
dataAdapter.SelectCommand.CommandText = "SELECT * FROM t1";


dataAdapter.UpdateCommand = new SqlCommand();
dataAdapter.UpdateCommand.Connection = conn;
dataAdapter.UpdateCommand.CommandText = "UPDATE t1 set name = 'changed5!!!' where 2=1";



dataAdapter.Fill(ds);

ds.Tables[0].Rows[0]["name"] = "ovidiu"; // Rowsate changes from Unchanged to Modified

dataAdapter.Update(ds); // update calls the update command
// in our case, the command does not have parameters, though it typically should

Monday, February 19, 2007

Showing Class Property in debugger tooltip

When you're in debug mode and move the mouse over a variable, you cang put any property value of that class you want like this:


[System.Diagnostics.DebuggerDisplay("Name = {Name}")]
public class Option
{
private string name = string.Empty;
public string Name
{
get { return name; }
}

}