如果不再存在,请将文本框值保存到数据库中 [英] SAVING TEXT BOX VALUE IN TO DATABASE IF NOT EXISTS AGAIN
本文介绍了如果不再存在,请将文本框值保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨这很小但是我很新,所以请指导
i有一个文本框,我将保存其值数据库如果单击按钮时不为空,但这里是我需要帮助我保存的值是否已存在于数据库表中我应该在我的屏幕记录上得到一条消息已经存在...请建议
解决方案
试试这个代码......
<前lang =c#> qry = select * from department_master其中dep_code =' + txt_code_add.Text + ';
sql_cmd = new SqlCommand(qry,sql_con);
sql_con.Open();
sql_rs = sql_cmd.ExecuteReader();
if (sql_rs.Read())
{
// *代码已存在,请更改您的代码;
}
else
{
// 写插入查询
}
i希望这段代码对你有所帮助..
你必须检查首先在表格中使用if条件...... :)
如果 (选择 * 来自用户其中 name = @name<> ' ')
BEGIN
INSER INTO ......
END
hi this is small but i am new so please guide
i had one textbox which i will be saving its value in to the databse if it is not null on click of button but here is i need help the value which i am saving is if already exists in the databse table i should get a message on my screen record already exists...please suggest
解决方案
try this code...
qry = "select * from department_master where dep_code='" + txt_code_add.Text + "'"; sql_cmd = new SqlCommand(qry, sql_con); sql_con.Open(); sql_rs = sql_cmd.ExecuteReader(); if (sql_rs.Read()) { //"*The code already existing,Please change your code"; } else { //Write insert query }
i hope this code helps you a bit..
You have to check first in table with if condition...:)
if(select * from users where name=@name <> '') BEGIN INSER INTO...... END
这篇关于如果不再存在,请将文本框值保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文