日期:2014-05-18 浏览次数:21003 次
string sql = "SELECT 备注,REPLACE([备注],'哈哈','哈哈谢谢')AS 新备注 FROM Sheet1"; DataSet ds = new DataSet(); OleDbDataAdapter da = new OleDbDataAdapter(sql, mycon); da.Fill(ds, "Sheet1"); this.dataGridView1.DataSource = ds.Tables[0];
declare @tab table ( [备注] NVARCHAR(30) ) insert into @tab select 'abc哈哈fghi哈哈3rw' SELECT [备注],REPLACE([备注],'哈哈','哈哈谢谢') AS 新备注 from @tab /* 备注 新备注 ------------------------------ -------------------------------- abc哈哈fghi哈哈3rw abc哈哈谢谢fghi哈哈谢谢3rw (1 行受影响) */
------解决方案--------------------
你这样试试看
string sql = "SELECT 备注,left([备注], instr([备注], '哈哈')) + '哈哈谢谢'+ right([备注], len([备注]) - instr([备注], '哈哈') - len('哈哈')) AS 新备注 FROM Sheet1"; DataSet ds = new DataSet(); OleDbDataAdapter da = new OleDbDataAdapter(sql, mycon); da.Fill(ds, "Sheet1"); this.dataGridView1.DataSource = ds.Tables[0];