我写的一段代码(莫名其妙)
存储过程:
Create PROCEDURE dbo.selectinteractivetxt
@size int
AS
begin
declare @sqlstr nvarchar(300)
set @sqlstr='select top'+str(@size)+' id,WebName,WebDomain,txtCount FROM WeberInteractive WHERE (Status = 1) ORDER BY txtCount%100'
exec(@sqlstr)
end
RETURN
Create PROCEDURE dbo.updateinteractivetxtcount
@id bigint
AS
update WeberInterActive set txtCount=txtCount+1 where id=@id
RETURN
public StringBuilder GetTxt()
{
string StyleType;
StringBuilder builder = new StringBuilder();
SqlCommand mySqlCommand = new SqlCommand();
mySqlCommand.CommandType = CommandType.StoredProcedure;
mySqlCommand.CommandText = "selectinteractivetxt";
mySqlCommand.Connection = mySqlConnection;
mySqlCommand.Parameters.Add(new SqlParameter("@size", SqlDbType.Int)); //add parameter @size
mySqlCommand.Parameters["@size"].Value = 1; //数量
SqlCommand mySqlCommand1 = new SqlCommand();
mySqlCommand1.CommandType = CommandType.StoredProcedure;
mySqlCommand1.CommandText = "updateinteractivetxtcount";
mySqlCommand1.Connection = mySqlConnection;
SqlDataAdapter MydataAdapter = new SqlDataAdapter();
MydataAdapter.SelectCommand = mySqlCommand;
MydataAdapter.UpdateCommand =mySqlCommand1;
SqlParameter id = MydataAdapter.UpdateCommand.Parameters.Add("@id",SqlDbType.BigInt);
id.SourceColumn = "id";
id.SourceVersion = DataRowVersion.Original;
DataSet ds = new DataSet();
OpenSql(mySqlConnection);
MydataAdapter.Fill(ds,"table1");
CloseSql(mySqlConnection);
builder.Append("<marquee>");
foreach (DataRow dr in ds.Tables["table1"].Rows)
{
builder.Append("<a href=" + dr["WebDomain"].ToString() + ">" + dr["WebName"].ToString() + dr["txtCount"] + "<a/> ");
dr["txtCount"]=10;
}
MydataAdapter.Update(ds, "table1");
builder.Append("</marquee>");
return builder;
}