我正在尝试编写一个视图并从该视图中检索数据,我已经这样做了:
string command = "if OBJECT_ID('try1') IS NOT NULL Drop view try1" +"\n"+"go"+"\n";
command = command + "Create view try1 as select WBSCode,Description,TerritoryCode,AmountReleased,convert(varchar(25),CreatedOn,106) as CreatedOn,IsEnable from WBS where WBSCode like '%" + msrch + "%'";
command = command +"\n"+"go"+"\n"+"select WBSCode,Description,TerritoryCode,AmountReleased,convert(varchar(25),CreatedOn,106) as CreatedOn,IsEnable from try1 where TerritoryCode in (select TerritoryCode from Territory where StateCode='" + mbcode + "')";
SqlCommand cmdd = new SqlCommand(command);
cmdd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(cmdd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
mngwbsGV1.DataSource = dt;
mngwbsGV1.DataBind();
}
但问题是我遇到了一个错误da.Fill(dt)
:
'go' 附近的语法不正确。
'CREATE VIEW' 必须是查询批处理中的第一条语句。
'go' 附近的语法不正确。
但是当我在我的 SQL Server 2008 中运行它时,它正在运行但没有检索数据
我该怎么办?