C#执行存储过程
//連接數據庫
????????SqlConnection?conn?=?new?SqlConnection();
????????conn.ConnectionString?=?"Data?Source=KARL;Initial?Catalog=ER;Persist?Security?Info=True;User?ID=sa;Password=sa";
????????SqlCommand?command?=?new?SqlCommand("proc_getMovieID",?conn);
????????conn.Open();
????????command.CommandType?=?CommandType.StoredProcedure;
????????command.Parameters.Add("@movieName",?SqlDbType.NVarChar,?50);
????????command.Parameters["@movieName"].Value?=?movieName;
????????SqlDataAdapter?da?=?new?SqlDataAdapter();
????????da.SelectCommand?=?command;
????????DataSet?ds?=?new?DataSet();
????????da.Fill(ds,?"tables");
????????//計算movieID
????????Int32?movieID;
????????if?(ds.Tables[0].Rows.Count?==?0)
????????????movieID?=?-1;
????????else
????????????movieID?=?int.Parse(ds.Tables[0].Rows[0][0].ToString());
????????//關閉數據庫
????????conn.Close();
????????return?movieID;
????????SqlConnection?conn?=?new?SqlConnection();
????????conn.ConnectionString?=?"Data?Source=KARL;Initial?Catalog=ER;Persist?Security?Info=True;User?ID=sa;Password=sa";
????????SqlCommand?command?=?new?SqlCommand("proc_getMovieID",?conn);
????????conn.Open();
????????command.CommandType?=?CommandType.StoredProcedure;
????????command.Parameters.Add("@movieName",?SqlDbType.NVarChar,?50);
????????command.Parameters["@movieName"].Value?=?movieName;
????????SqlDataAdapter?da?=?new?SqlDataAdapter();
????????da.SelectCommand?=?command;
????????DataSet?ds?=?new?DataSet();
????????da.Fill(ds,?"tables");
????????//計算movieID
????????Int32?movieID;
????????if?(ds.Tables[0].Rows.Count?==?0)
????????????movieID?=?-1;
????????else
????????????movieID?=?int.Parse(ds.Tables[0].Rows[0][0].ToString());
????????//關閉數據庫
????????conn.Close();
????????return?movieID;
轉載于:https://www.cnblogs.com/fishert/archive/2007/04/27/729969.html
總結
- 上一篇: [转]网上收集的Html颜色代码全集
- 下一篇: 解决2003不支持FLV的方法