---
title: "检验数据库中是否有特定记录的最简单方法"
author: "mywebcode"
date: "2008-11-12T21:43:00Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2013-05-08T10:14:43Z"
id: 1862529
url: "https://mywebcode.iteye.com/blog/1862529"
---

String sqlconn = "Data Source=wei//SQLEXPRESS;Initial Catalog=HISDB;Integrated Security=True";  
SqlConnection weida = new SqlConnection(sqlconn);  
weida.Open();  
//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\**  
string sql = "SELECT tkdh FROM tkxx WHERE checked = 'True' AND tkdh='" + ckdh + "'";

SqlCommand check1 = new SqlCommand(sql, weida);

int j = Convert.ToInt32(check1.ExecuteScalar());  
if (j &gt; 0) //存在  
{  
Response.Write("&lt;script language='javascript'&gt;alert('该出库记录已经执行退库操作,不能重复退库');&lt;/script&gt;");  
}  
else  
{

}