C# 数据库写入简单示例

 private int UpdateDB(string fname, string md5, int type)

        {

            string sql = @"insert into tb_hash(fname, uuid, state) values(@fname, @uuid, @state)";

            SqlParameter[] parameters = {

                                            new SqlParameter("@fname", fname),

                                            new SqlParameter("@uuid", md5),

                                            new SqlParameter("@state", type)

                                        };



            string conStr = @"server=.\sqlexpress;database=batchseal;uid=sa;pwd=111111";

            SqlConnection conn = new SqlConnection(conStr);

            conn.Open();

            SqlCommand cmd = new SqlCommand(sql, conn);

            cmd.Parameters.AddRange(parameters);

            int ret = cmd.ExecuteNonQuery();



            return ret;

        }

 

你可能感兴趣的:(数据库)