Click here to Skip to main content
14,330,747 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have two databases.And I have one textbox.
I want to make the student add the values ​​entered in the textbox according to which database it exists. Add expression is ok. But I could not write query for control. How can I write.

For example

School1 database

School1.classtable
Classıd  classno   classcityıd
  15          70        10
  89          55        78


School2 database

School2.classtable

Classıd  classno   classcityıd
  17          50        19
  89          85        96


Entered to textbox is values(classıd+classno+classcityıd).And I want to check and then if I want to register in which database.

For example entered values: 895578 and 175019

//check values control

If the table value in the first database contains the value entered by the insert method 1. If the table value contains 2, then it should be saved to 2 by insert method.

SqlConnection con = new SqlConnection(mycon1);

//895578 is include database1.So add method is this value.
public void Add()
{


}


SqlConnection con = new SqlConnection(mycon2);

//175019 is include database2.So add method is this value.

public void Add()
{


}


Note:Textbox binding is textlist. So textlist values is (895578 and 175019)

What I have tried:

database1.School1.Select(t => new { School1 = t.Classıd+t.Classno+t.Classcityıd });

database2.School1.Select(t => new { School1 = t.Classıd+t.Classno+t.Classcityıd });
Posted
Updated 9-Oct-19 22:29pm
v3
Comments
Maciej Los 9-Oct-19 16:57pm
   
Sorry, but your question is unclear. Can you be more specific and provide more details?
Rate this:
Please Sign up or sign in to vote.

Solution 1

False economy.

You have 3 fields / columns; therefore, you should have 3 text boxes ... not ONE textbox containing a concatenated string you now have to split in order to create a meaningful query.

You're painting yourself into a corner.
   
Comments
Maciej Los 10-Oct-19 4:13am
   
This answer does NOT resolve OP's issue, but - for sure - it deserves for 5!
Rate this:
Please Sign up or sign in to vote.

Solution 2

Quote:
I want to make the student add the values ​​entered in the textbox according to which database it exists.

If understand you well, you want to add student information to the corresponding database, but you did not provide enough information about database choose process.

If you want to let user to choose a database in which data will be saved, you can add combobox with database name. Then, depending on user choice, you'll be able to add data into proper database. In pseudo code:
if(ComboBox1.SelectedValue.ToString() == "School1")
    'insert data into School1 database
else
    'insert data into School2 database


Note: This is NOT a perfect solution, due to several reasons.
I'd rather let user to choose the database context on application start.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100