473,383 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

web part not getting connected with the database

11
hi all,
i hav created a webpart for inserting a record in asp.net ,c# and deploy it in sharepoint.. my code is executing properly.. when i deploy it it asks for insert new record and wen i get the details and click insert the values are not getting stored in sql server database.. could any one point me out what s wrong in the program..i hav posted my prog below

Thanks
Sri

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Web.UI;
  3. using System.Web.UI.WebControls;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Configuration;
  7. using System.Web;
  8. using System.Security;
  9. using System.Web.Security;
  10. using Microsoft.SharePoint.WebPartPages;
  11. using System.Web.UI.HtmlControls;
  12. using System.Data.SqlClient;
  13. using System.Xml;
  14. using System.Security.Permissions;
  15.  
  16. namespace dweb
  17. {
  18.     /// <summary>
  19.     /// Summary description for WebCustomControl1.
  20.     /// </summary>
  21.     [DefaultProperty("Text"),
  22.     ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
  23.     public class dweb:WebPart
  24.     {
  25.  
  26.         //private string text;
  27.  
  28.         [Bindable(true),
  29.         Category("Appearance"),
  30.         DefaultValue("")]
  31.  
  32.         Label lid=new Label();
  33.         TextBox txtid=new TextBox();
  34.         Label lfname=new Label();
  35.         TextBox txtfname=new TextBox();
  36.         Label lname=new Label();
  37.         TextBox txtlname=new TextBox();
  38.         Label addr=new Label();
  39.         TextBox txtaddr=new TextBox();
  40.         Label email=new Label();
  41.         TextBox txtemail=new TextBox();
  42.         TextBox txtphno=new TextBox();
  43.         TextBox txtdesig=new TextBox();
  44.         TextBox txtsal=new TextBox();
  45.         TextBox txtqual=new TextBox();
  46.         TextBox txtage=new TextBox();
  47.  
  48.  
  49.         SqlConnection con;
  50.  
  51.         protected override void CreateChildControls()
  52.         {
  53.             Button insert=new Button();
  54.             insert.Text="Insert New Record";
  55.             insert.ID="create";
  56.             Controls.Add(insert);
  57.             Controls.Add(new LiteralControl("<br>"));
  58.             insert.Click+=new EventHandler(create_Click);
  59.  
  60.             EnsureChildControls();
  61.         }
  62.  
  63.         private void create_Click(object sender, EventArgs e)
  64.         {
  65.  
  66.  
  67.             lid.Text="Enter ID:";
  68.             Controls.Add(lid);
  69.             Controls.Add(txtid);
  70.             Controls.Add(new LiteralControl("<br>"));
  71.             lfname.Text="First Name:";
  72.             Controls.Add(lfname);
  73.             Controls.Add(txtfname);
  74.             Controls.Add(new LiteralControl("<br>"));
  75.             lname.Text="Last Name:";
  76.             Controls.Add(lname);
  77.  
  78.             Controls.Add(txtlname);
  79.             Controls.Add(new LiteralControl("<br>"));
  80.  
  81.             addr.Text="Address:";
  82.             Controls.Add(addr);
  83.  
  84.             Controls.Add(txtaddr);
  85.             Controls.Add(new LiteralControl("<br>"));
  86.  
  87.             email.Text="Email Id:";
  88.             Controls.Add(email);
  89.  
  90.             Controls.Add(txtemail);
  91.             Controls.Add(new LiteralControl("<br>"));
  92.             Label phno=new Label();
  93.             phno.Text="Phone No:";
  94.             Controls.Add(phno);
  95.  
  96.             Controls.Add(txtphno);
  97.             Controls.Add(new LiteralControl("<br>"));
  98.             Label desig=new Label();
  99.             desig.Text="Designation:";
  100.             Controls.Add(desig);
  101.  
  102.             Controls.Add(txtdesig);
  103.             Controls.Add(new LiteralControl("<br>"));
  104.             Label sal=new Label();
  105.             sal.Text="Salary:";
  106.             Controls.Add(sal);
  107.  
  108.             Controls.Add(txtsal);
  109.             Controls.Add(new LiteralControl("<br>"));
  110.             Label qual=new Label();
  111.             qual.Text="Qualification:";
  112.             Controls.Add(qual);
  113.  
  114.             Controls.Add(txtqual);
  115.             Controls.Add(new LiteralControl("<br>"));
  116.             Label age=new Label();
  117.             age.Text="Age:";
  118.             Controls.Add(age);
  119.  
  120.             Controls.Add(txtage);
  121.             Controls.Add(new LiteralControl("<br>"));
  122.             Button btncreate=new Button();
  123.             btncreate.Text="INSERT";
  124.             btncreate.ID="insertbtn";
  125.             Controls.Add(btncreate);
  126.             btncreate.Click +=
  127.                 new EventHandler(insertbtn_Click);
  128.         }
  129.  
  130.         [AspNetHostingPermission(SecurityAction.Demand,             Level=AspNetHostingPermissionLevel.Unrestricted)]
  131.          [AspNetHostingPermissionSecurityAction.InheritanceDemand,             Level=AspNetHostingPermissionLevel.Unrestricted)]
  132.  
  133.     private void insertbtn_Click(objectsender,EventArgs e)
  134.             {
  135.  
  136. con = new SqlConnection("Data Source=WSINTRA13;Initial Catalog=pubs; User ID=Insite.user;Password=insiteslc1");
  137. string cmd = "insert into emp_details(e_id,fname,lname,address,email_id,ph_no,designation,salary,qualifictn,age) values( '" + txtid.Text + " ','" + txtfname.Text +  " ','" + txtlname.Text + "','" + txtaddr.Text+ "','" +txtemail.Text+ "'," +txtphno.Text+ ",'" +txtdesig.Text+ "'," +txtsal.Text+ ",'" +txtqual.Text+ "'," + txtage.Text + ")";        
  138.  
  139.  
  140.                SqlCommand scmd = new SqlCommand(cmd,con); 
  141.     scmd.CommandText=cmd;
  142.     con.Open();
  143.     scmd.ExecuteNonQuery();
  144.     con.Close();
  145.  
  146.                }
  147.  
  148.     }
  149. }
  150.  
Mar 11 '09 #1
0 1341

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: James | last post by:
Please help - getting very desperate! Sun, 12 October 2003 05:39 I have PHPDEV 4.2.3 from Firepages.com.au as the upgrade to 4.3.0 did not work. I also had an abortive download from PHP.NET as...
0
by: ʹÃûÑï | last post by:
ORA-03114: not connected to ORACLE && MS's Bug?? DataBase:Oracle 817 using OracleClient,net framework 1.1 I'm using ADO.Net in C# with Oracle 817. and following is my public data access...
2
by: Robert Scheer | last post by:
Hi. My site needs to know if the user is connected before executing some queries on my database. Actually, I have a page loaded by an Iframe that runs every 30 seconds and updates a field on my...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
1
by: Developer | last post by:
Dear Group Member, I am sorry if I have posted this query in wrong group, but since this is connected with ASPO.NET2.0, thought of posting here. I am doing a very simple program where I am...
10
by: bill | last post by:
I have a database of kennels. One page lists the kennels alphabetically by kennel name. I have a field for kennel name and an index with kennel name as the only field. Some of the kennels have...
9
by: christopher_board | last post by:
Hi all. I am trying to write a php page which connects to a MySQL Database which is supposed to get the results from a table within a database and display the results in a table. Below is the...
1
by: odrap | last post by:
I wrote a ADO.NET ( VB.NET language) database application with the data database itself located on a SQL SERVER 2005 Express on my desktop. The application database is on my laptop. My laptop as...
3
by: rpupkin77 | last post by:
Hey, How does one going about their user's geographical location? Is that even a PHP question. For example, a site may say "Find others near Boston", but if you were in New York, it would say...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.