Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update a SQL Server Table

Status
Not open for further replies.

gslick

Programmer
Sep 9, 2004
18
GB
Hi,

I have been trying to find out how to update a table in SQL Server 2005 using (CLR).

This is my class

public static void UpdateDatabase()
{
string Name;

using (SqlConnection conn =
new SqlConnection("context connection = true"))
{
conn.Open();


SqlCommand cmd = new SqlCommand(
"SELECT A,B FROM dbo.Table", conn);

SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
Name = reader.GetString(0);
string Query = String.Format(
"UPDATE Table SET A = '{0}1' WHERE A = '{0}'",A);
SqlCommand cmdupd = new SqlCommand(
Query, conn);
SqlContext.Pipe.ExecuteAndSend(cmdupd);
reader.NextResult;
}
reader.Close();
conn.Close();
}


This does not work, can somebody help ?

Thanks
 
Are you trying to deploy this to SQL Server? If so, can you show your entire class, not just this method?

Hope it helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top