I am trying to execute some SQL code, connected directly to my database, but I don’t know how to execute the query.
x
SqlConnection connect = new SqlConnection("DATABASE");
SqlConnection myConnection = connect;
connect.Open();
SqlDataAdapter adptador = new SqlDataAdapter(@"QUERY", connect);
DataTable tabela = new DataTable();
adptador.Fill(TABLE);
clientContext.Web.Lists.GetByTitle("TITLE");
clientContext.ExecuteQuery();
List list = clientContext.Web.Lists.GetByTitle("LISTNAME");
clientContext.Load(list);
ListItemCreationInformation listItemCreationInformation = new ListItemCreationInformation();
ListItem item = list.AddItem(listItemCreationInformation);
foreach (DataRow row in tabela.Rows)
{
item["LastModifiedBy"] = row["LastModifiedBy"].ToString();
item.Update();
cm = new SqlCommand("SQL COMMAND");
**EXECUTE CM**
clientContext.ExecuteQuery();
}
Advertisement
Answer
SqlCommand has ExecuteReader, for executing the command and returning a dataset, ExecuteScalar for returning a single value of a primitive type (int, string, etc.), or executeNonQuery for returning nothing. You can also pass a command to a SqlDataAdapter, and use that to populate a DataTable object.
Please google SqlCommand and you will find LOTS of examples.