Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i wrriten my design code in javascript i dont know how to write the database connectivity in c#
Posted
Comments
OriginalGriff 23-Nov-13 7:17am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
bjdestiny 23-Nov-13 7:19am    
what is you exact problem??? java script or database???

1 solution

If you want to communicate your database from your application c#code then you can take ADO.net(.NET framework component for data access) help. There are so many classes are there two access database. For example SqlConnection, SqlCommand, SqlDataReader, SqlDataAdapter etc for Sql Server specific component. Code sample as follows:

C#
string connectionString = "Data Source=192.168.1.4; Initial Catalog=your_databaseName; User Id=sa; Password=****";
            using(var conn = new System.Data.SqlClient.SqlConnection(connectionString))
            {
                using(System.Data.SqlClient.SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT Id, Name FROM MyTable";
                    cmd.CommandType = CommandType.Text;

                    cmd.Connection.Open();
                    System.Data.SqlClient.SqlDataReader dataReader = cmd.ExecuteReader();
                }
            }
connectionString is the actual database path where your database is located and authentication information.

From your client side javascript function you can not access database directly. If you need so then you can write webserivice/wcf/webapi and then from your javascript function you will call that webservice with ajax calling.
 
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