TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Raja Khoury
NA
10
6.1k
Coding help: Connection string /objects to SQL and retrieve Data in VS ( C#)
Jun 20 2012 9:50 AM
I am new to C# and VB, I am working on a personal project but facing challenges with the coding. I have read many articles on C# & Sql coding etc.. but when it comes to creating the application there's always an error if you don't know well the logic behind it. I need some sort of guidance if possible.
The idea is to create a windows app form (C#) where there will be a textbox1 ( user inputs word) ; a search button and textbox2 ( display of query result). It's a virtual search engine/ dictionary that uses SQL database as source of information. This is what I have reached so far;
1 - Created a table ( SQL server) with Two fields ( Word ; Definition) and added around 200 words in it. Shall I create a relationship diagram to the table I created and set 'word' as primary key? Or it is not necessary?
2- Establish a connection string in VB (c#) ;
using System.Data.Sql;
using System.Data.SqlClient;
SqlConnection myConnection = new SqlConnection("user id=userid;" + "password=validpwd;server=localhost;" + "Trusted-connection =yes;" + database=main; "+ connection timeout=30");
If it's a windows authentication log in SQl can I remove the userid and password? How Can I verify the connection is working?
3- under Click-Button event
private void button1Click(object sender, EventArgs e)
{
string connectionString = "Initial Catalog=main;Data Source=(local);Integrated Security=SSPI;";
SqlConnection cn = new SqlConnection(connectionString);
string sCommand = "SELECT definition FROM Dictionnary WHERE word ='"+ TextBox1.Text.Trim()+"'",Sqlcon;
4 - What is the simplest solution for such a query? take the input text in textbox1 then search the SQl table then display it in textbox2?
I am afraid that the problem might lie in setting up the table data in SQL that's why I had connection errors, is my progress logical?
Thanks alot,
Reply
Answers (
3
)
synchronize a SQL Server database with its remote client databases
Testing text of a label in Visual C#