string con =(string) ConfigurationManager.ConnectionStrings["WindowsFormsApplication1.Properties.Settings.Database1ConnectionString"].ConnectionString;
//string con = Properties.Settings.Default.Database1ConnectionString;
string sql = "SELECT category.Id, category.category, book.bookid FROM category INNER JOIN book ON category.Id ="+m;
SqlCommand com = new SqlCommand();
com.CommandText = sql;
com.Connection = con;
con.Open()
{
com.EndExecuteNonQuery()
con.close;
}
答案 0 :(得分:4)
Connection
属性为SqlConnection,而变量con
包含string。
以下是如何使其发挥作用:
using (var connection = new SqlConnection(con))
{
connection.Open();
using (var command = new SqlCommand(sql, connection))
{
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
// your logic to process the response
}
}
}
}