【发布时间】:2011-08-12 18:35:50
【问题描述】:
我发现 mysqli_stmt_prepare() 函数在 PHP 中使用准备好的语句。 SQL-Server 的 C# 中是什么样的? 我找到了这个代码示例(使用参数化命令)。这就是我要找的吗?
SqlConnection conn = new SqlConnection();
SqlCommand com = new SqlCommand();
SqlDataAdapter dap = new SqlDataAdapter();
DataTable tbl = new DataTable();
SqlParameter param = new SqlParameter();
conn.ConnectionString = @"Data Source=...";
com.Connection = conn;
com.CommandText = "select * from tbl1 where id<@id";
com.Parameters.AddWithValue("@id",4);
com.CommandType = CommandType.Text;
dap.SelectCommand = com;
conn.Open();
dap.Fill(tbl);
conn.Close();
dataGridView1.DataSource = tbl;
如果不是,那是什么?
如果是,请告诉我如何使用字符“?”而不是在命令文本中写入@id。
谢谢
【问题讨论】:
标签: c# php sql-server prepared-statement sqlcommand