473,569 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

web part not getting connected with the database

11 New Member
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 1350

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

Similar topics

3
2574
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 I could not configure Apache myself. The REAL problem is that PHPmyAdmin works and sees my test database Wines.... But my PHP program does not!
0
5768
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 class. using System.Data.OracleClient;
2
2307
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 database to tells me the user is connected. If this field is not updated for more than one minute I consider the user disconnected. The problem...
0
3700
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) : base(message){} public FtpException(string message, Exception innerException) : base(message,innerException){}
1
1618
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 inserting Grid control, SQL datasource control. I am attaching the default Northwind database to this Sql Datasource and binding this to the grid...
10
1465
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 the word "The" as the first word in the name and they do not want to be listed alphabetically by "The..." Is there a way that I can request that...
9
2772
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 code that I am using: <?php function connectDatabase() { $dbhost = 'localhost'; $dbuser = 'root';
1
1653
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 well as my desktop are connected to the internet. (cable -Telenet ) I have heard that the provider regulary change my IP address,and that's precisely...
3
1714
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 "Find others in New York" Thanks.
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.