开发者

how to check whether the textbox1 and textbox2 entered value is present in database record or not using vb.net?

My Database field :

ID            Name                Age

1             Sumit               23
2             Manish              25
3           开发者_JS百科  John                22

i have two textboxes and 1 button and label1 in my asp.net webform ...

when i enter Sumit in textbox1 and 23 in textbox2 then it validates the database to check whether then value entered in textbox1 is present in Name column of database and 23 is present in Age column of database....then it redirect to ~.Default2.aspx else shows error message in label ...


You have to make and SQL command which does something like:

SELECT * WHERE Name = 'Sumit' AND Age=23

And then check if the command returns anything. If it did, then it means that the value is already there.


In the database connectivity,

Try this Query in your SqlCommand Object,

select 1 from tablename where Name = ' + TextBox1.Text + ' and Age = ' + TextBox2.Text + '.

I hope it will help.


I think this code might solve your problem. Convert this code using online C# to vb.net converter

SqlConnection cnn = new SqlConnection(yourConnectionString);
string query = "select count(*) from tableName where Name='"+textBox1.Text+"' and Age="+textboox2.Text;
SqlCommand cmd = new SqlCommand(query, cnn);
cnn.open();
if(cmd.ExecuteScalar>0)
{
//Record Exists
return;
}
//Record doesn't exist

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜