如何检查SQL中是否可用的表中的值? [英] how to check the values in the table which is avail or not in sql?
本文介绍了如何检查SQL中是否可用的表中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用于登录....我在注册表中将值输入为rollno.
for login.... i entered the values as rollno in the registration table. how could i chek the input for login, entering rollno with the values present in the registration table?
推荐答案
private void txtCourseName_Leave(object sender, EventArgs e)
{
SqlCon = DBCon.DBOpenConnection();
Query = "Select distinct Name from tblDepartmentMaster";
SqlCmd = new SqlCommand(Query, SqlCon);
SqlDr = SqlCmd.ExecuteReader();
while (SqlDr.Read())
{
txtName.Text = SqlDr.GetString(0).ToString();
}
MessageBox.Show("Already Exist the Name!", "Already Exist", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtCourseName.Clear();
ActiveControl = txtCourseName;
SqlDr.Close();
}
if (btnSave.Text == "Save")
{
SqlCommandBuilder cmdbSection;
DataRow newrow;
ds = new DataSet();
ad = new SqlDataAdapter("select strTestName from PEHMstTest where strTestName='" + txttestname.Text + "'", SqlCon);
ad.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
DataSet ds1 = new DataSet();
SqlDataAdapter ad1 = new SqlDataAdapter("select * from PEHMstTest", SqlCon);
ad1.Fill(ds1);
newrow = ds1.Tables[0].NewRow();
newrow[0] = new_num();
newrow[1] = txttestname.Text;
newrow[2] = txtcharges.Text;
ds1.Tables[0].Rows.Add(newrow);
cmdbSection = new SqlCommandBuilder(ad1);
ad1.Update(ds1);
lblMsg.ForeColor = Color.Green;
lblMsg.Text = "Records saved successfully";
}
else
{
lblMsg.ForeColor = Color.Red;
lblMsg.Text = "Test Detail Already Exists, Give a different name.";
}
}
[edit]添加了前置标记[/edit]
[edit]added pre tag[/edit]
DataSet ds = new DataSet();
SqlDataAdapter ad = new SqlDataAdapter("select * from technicalregistration where strloginname='" + txtusername.Text + "' and strloginpwd='" + txtpassword.Text + "'", sqlcon);
ad.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
Response.Redirect("Somepage.aspx");
}
else
lblmessage.Text = "Invalid UserName and Password";
txtusername.Text = "";
txtpassword.Text = "";
你可以去这里
添加了前置标记[/编辑]
You can go for this
added pre tag[/Edit]
这篇关于如何检查SQL中是否可用的表中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文