用C#查询数据库所有表名,cmd.CommandText不会写,搞不清字符串里所含的单双引号、字符串子串、字符的关系
想用C#查询数据库所有表名存于table字符串数组中
代码如下:
lstDatabase = new List<string>();
strConn = "Data Source=8LMCHPS0OIHHFIZ\\SQLEXPRESS;Initial Catalog=DaFengShuLingDBInputOut;Integrated Security=True;Pooling=False";
sqlConn = new SqlConnection(strConn);
sqlConn.Open();
sqlCom = new SqlCommand();
sqlCom.CommandText = "select * from sys.Objects where type = u";
dr = sqlCom.ExecuteReader();
while (dr.Read())
{
tableCount = dr.FieldCount;
table = new string[tableCount];
for (int index = 0; index < dr.FieldCount; ++index)
{
table[index] = (string)dr[index]; //将object型转换成string型
}
}
addDatabase(database, table);
sqlConn.Close();
出错提示:
另外,像以下这条查询字符串
strSql = "insert concretestrain(observedate, observevalue, crosssetion, instrumentnumber, leftorrightline) values('" + row[0] + "','" + row[1] + "','" + row[2] + "','" + row[3] + "','" + row[4] + "')";
怎么理解啊,其中row[i]是字符串变量,字符串内部的加号、单引号、双引号要在什么情况下才使用的? 求大神帮忙~~~
linyp
12 years, 8 months ago