Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

C#
SqlConnection con = new SqlConnection(mycon1);

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


}


C#
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:

C#
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?

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.
 
Share this answer
 
Comments
Maciej Los 10-Oct-19 4:13am    
This answer does NOT resolve OP's issue, but - for sure - it deserves for 5!
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:
VB
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.
 
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