Click here to Skip to main content
15,885,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This will be a great help for me to carry my project further.

I need to check the text box value(form) with database. If it exist I try to show warning message and if not ask the user to enter the values.

I try to implement this code with Windows form,MVC format.

Can you give sample code for this? Any suggestion ideas?


Thank You.
Posted
Updated 6-Nov-14 9:02am
v2
Comments
BillWoodruff 6-Nov-14 14:51pm    
Welcome to CodeProject !

What user action with the TextBox do you want to use to trigger the query of the DataBase ?

That action should raise an Event to the Controller, then the Controller interacts with the DataBase, and updates the View (Form, TextBox) as necessary: correct ?

Please show some code, or describe what you are doing now in more detail.

A small suggestion. One thing you can do is, On focus out from the textbox retrieve the value using its id like
$("#textboxId").val();
based on that value make an ajax call to the controller action if you are using MVC, where you would check if the textbox value exists or matches with the data from the database. If exists return true else if false then alert that the user needs to add the values. This is what can be achieved through MVC in .NET.
Post back your queries if any.
Thanks
:)
 
Share this answer
 
Comments
BillWoodruff 7-Nov-14 2:19am    
Good idea, but I'd add the advice to perform simple validation in the View, and not trigger interaction with the Controller if the data is invalid.
[no name] 7-Nov-14 2:28am    
Yes Bill thats the best way to be done. But this would be possible on the post action, I think he needs to check once out of focus. Still we are anticipating , the man himself has no response.. ;)
sajee1 7-Nov-14 3:48am    
Hi..!
Thanks All;

This is about windows form. Not web form..Do you have idea..?
View:
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{

//textBox1.Text = controller.CheckAndGetBarcode();
MessageBox.Show(controller.CheckAndGetBarcode());

}
}
Model:

public class ProductModel
{
//public string s;


/*public string GetBarcode()
{


label_nameDataContext ptable = new label_nameDataContext();
var pr = from Product p in ptable.Products where p.Gtin == "8" select p;
foreach (var item in pr)
{
s = item.ProductCost.ToString();
}
return s;
}


}

Controller
public string CheckAndGetBarcode()
{
string returnvalue = "";
if (CheckAvailability())
{

ProductModel model = new ProductModel();
returnvalue = model.GetBarcode();
}
return returnvalue;
}

public bool CheckAvailability()
{
return true;
}

In model i gave 8 by manually...What i want to do is instance of 8 i want to get the value of textbox1.

Can u help me?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900