C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » Sharepoint »

Webpart values in Database


Posted Date: 30 Oct 2009      Posted By: geetha      Member Level: Bronze     Points: 1   Responses: 2



hi frnds...



i created a webpart in VS 2005 and i deployed in Shareppint site... the webpart has 4 text boxes and a button...

it is like a small registration page...


i want to enter some values in those textboxes and if i click save button it should save all values in sql 2005 table.....

how to approach this....


where to give the connection string....




plese help me....
thanx in advance





Responses

Author: R.M.Phani Kumar    02 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Hi Geetha
Its Pretty simple...just follow the below steps

1.create a VS-2003/05/08 web application with a sample name
2.add a userControl with sample name like frmSave.ascx
3.Add the controls like you mentioned (4 text boxes and 1 save button)
4.In the click event of the button write the corresponding logic as in dotnet development.

Once the above steps are completed

5. now add the user control to the web part as shown below in CreateChildControls method.

Code part
UserControl ucSampleWP = null;
protected override void CreateChildControls()
{
try
{
this.ucSampleWP = (UserControl)Page.LoadControl(@"/styles/Controls/frmSave.ascx");
this.Controls.Add(this.ucSampleWP );
}
catch
{
throw;
}
}
6. Now compile you webpart and safe control entry in web.config

Copy the ascx file and codebehind file to \\YourServiverName\siteName\Styles\Controls folder.

add the webpart in desired page and see the result

Please revert further if u r facing any issue

Happy coding

Regards
Phani Kumar R M



Author: Pradeep Kumar    13 Nov 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

There are two ways of doing this.

1) You can hardcode connection string in you web part code and use SqlConnection and SqlCommand object to do database operation like you normally do in asp.net application.

2) Define connection string in sharepoint application web.config file like you normally do in asp.net application web.config and red it using below code.
Configuration config = WebConfigurationManager.OpenWebConfiguration("/", this.WebApplication.Name);
string _sqlConnectionString = config.ConnectionStrings.ConnectionStrings["DBConnectionString"].ToString();


The second was is preferable, because you can configure connection string which can be modified any time.



Post Reply
You must Sign In to post a response.
Next : I need to know share points in dot net
Previous : Hyperlinks are not working in excel sheet in sharepoint
Return to Discussion Forum
Post New Message
Category: Sharepoint

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use