Hi Ppl, I come from a PHP programming background, I also know classic asp 3 very well. Now, I wanna learn ASP.net, Last night I was going through an ASP.net Ebook, But the connection string given in that book had many lines of code and confusing too. In PHP or classic asp, we had 1 or just 2 line of code for connecting to the DB (in VB and C#). Can someone please tell me a connection code with a minimal line of code? Also, Since I am from a PHP background, Plz suggest me which language should I use for ASP.net (VB or C#)? Thanx
Here is the code to connect to a SQL Express database. The connection string should be placed in the web.config file. The database should be in the App_data folder of your application. <connectionStrings> <add name="ASPNETDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|MyDatabaseFileName.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" /> </connectionStrings> If you are coming from PHP, C# would be recommended because of the similar syntax
Hi Dear, The suggestion given by vihutuo is true and the recommendation for language is also true. but i give you a example. and also show you that where and how you have to write a code. The following code you have to write in webconfig between <configuration> tag like this. <configuration> <appSettings> <add key="CONNECTIONSTRINGNAME" value="server=SERVERNAME;database=DATABASENAME;uid=USERID;password=PASSWORD; integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient"/> </appSettings> </configuration> After that you can use them on any page by write simply on statement as follow: cn = new SqlConnection(ConfigurationManager.AppSettings["CONNECTIONSTRINGNAME"]); * here cn is a object of SqlConnection class. by using them you can open and close the connection.
ok thanx, but after making a connection, how do I insert a record and select record from the db? Plz guide? Thanx
If you are using Visual Studio, drag and drop the SQLDatasourceControl and then configure the control. Then you can drop any of the databound controls like gridview, formview, etc to dispay or insert records
Database operations are very simple in ASP.net you can find some sample code in http://techdotnets.blogspot.com/
Database operations are simple in ASP.NET but... what would you say if you have some Complex operations that cannot be done by using the SqlSources.. or ... will someone use more than 5 SqlDataSources on a page? Come on... if these Data Sources weren't able in ASP.NET, than it would be much harder than PHP. So... for you my friend, it's good to start using the SqlDataSources and other objects but I recommend u to start learning doing that with coding it... it would be the best way for u to understand and to be able to go above the frames of the framework