I have a ASP.Net Page with code behined in C#. as below -
<body>
-
<form id="form1" runat="server">
-
<table align=center >
-
<tr>
-
<td>
-
<asp:Label runat=server ID="lblCustomer">Customer Name: </asp:Label>
-
<asp:TextBox Style="color:Red" runat=server ID="txtCustomer" OnFocus="clearDefault(this)">Enter Customer Name</asp:TextBox>   
-
<asp:Button runat=server ID=cmdSubmit OnClick="cmdSubmit" Text="Create Customer"/>
-
</td>
-
</tr>
-
</table>
-
</form>
-
</body>
-
</html>
-
I am try to send the Customer name entered to a SQL DB but I am not sure how to process this on the C# page. I am new to this and do not quite understand. I have been able to retrive data in other apps but I can not seem to write to a SQL DB. Below is what I have in the code behind. -
using System;
-
using System.Data;
-
using System.Configuration;
-
using System.Linq;
-
using System.Web;
-
using System.Web.Security;
-
using System.Web.UI;
-
using System.Web.UI.HtmlControls;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.WebControls.WebParts;
-
using System.Xml.Linq;
-
using Conversion_Tool.Classes;
-
namespace Conversioin_Tool
-
{
-
public partial class CustomerCreation : System.Web.UI.Page
-
{
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
cmdCustomer_Click += new System.EventHandler(this.cmdCustomer_Click);
-
-
}
-
protected void cmdCustomer_Click(object sender, EventArgs e)
-
{
-
CustomerInsert(txtCustomer.Text).ToString;
-
}
-
protected void CustomerInsert(string Customer)
-
{
-
string SQLStr = "Insert into CT_Customers" +
-
" (Customer)" +
-
" Values('" + sCustomer + "')";
-
-
SqlConnection SqlConn = new SqlConnection (ConfigurationManager.ConnectionStrings["Conversion_Tool"].ToString());
-
-
try
-
{
-
//Try to open connection
-
SQLConn.Open();
-
-
//SQL Adapter
-
SqlDataAdapter da = new SqlDataAdapter(SQLStr, SqlConn);
-
-
//Cose Connection
-
SqlConn.Close();
-
}
-
-
}
-
}
-
}
-
4 3086 jhardman 3,406
Recognized Expert Specialist
You posted in the ASP classic forum, instead of the ASP.NET forum. I'll move it over for you, but next time please note that there is a really big difference between ASP and ASP.NET. No solutions I can give you in ASP will work in an ASP.NET website.
Jared
I hope this helps -
string strSql = "INSERT INTO CT_Customers(Customer) Values (@customer);
-
-
SqlConnection conn = new SqlConnection();
-
String constr = ConfigurationManager.ConnectionStrings[("COnversion_Tool")].ConnectionString;
-
conn = new SqlConnection(constr);
-
SqlCommand mycommand = new SqlCommand(strSql, conn);
-
-
SqlParameter cust = new SqlParameter("@customer", SqlDbType.VarChar);
-
mycommand.Parameters.Add(cust);
-
mycommand.Parameters["@customer"].Value = txtCustomer.Text; //value from the text box
-
-
try
-
{
-
conn.Open();
-
mycommand.ExecuteNonQuery();
-
}
-
catch (Exception ex)
-
{
-
throw ex; // Add you error msg display here
-
}
-
finally
-
{
-
conn.Close();
-
}
-
Frinavale 9,735
Recognized Expert Moderator Expert
For a quick overview of how to use a database in your application check out:
-Frinny
@Kratos2005
i send u some code just modify according to the table & u use, - public static void AddDummy(DummyBLL dummybll)
-
{
-
/* we can use any one of the statement for making an connection, currently we are using a connection string from web.config file.
-
SqlConnection con = new SqlConnection("Data Source=localhost\\SQLEXPRESS;Initial Catalog=mahesh;Integrated Security=True");*/
-
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
-
-
SqlCommand cmd = con.CreateCommand();
-
cmd.CommandText = string.Format("Insert into ManageClient(ClientName,Address,MobileNo,Image)Values(@ClientName,@Address,@MobileNo,@Image)");
-
con.Open();
-
cmd.Parameters.Add(new SqlParameter("@ClientName",dummybll.ClientName));
-
cmd.Parameters.Add(new SqlParameter("@Address",dummybll.Address));
-
cmd.Parameters.Add(new SqlParameter("@MobileNo",dummybll.MobileNo));
-
cmd.Parameters.Add(new SqlParameter("@Image",dummybll.Image));
-
cmd.ExecuteNonQuery();
-
con.Close();
-
}
After that call this method in aspx page its work,
u can use any one of the statements either direct use statements or make a connection string in web cinfig file
by the way we did the comment of direct methos i only use the connection string make in web.config file
u use the statement in aspx page is that
addclient(object) & call
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Fred Armitage |
last post by:
I have a fairly complex application written using a vb code-behind dll.
However, I'd like to write one particular aspx page utilising in-line code
so that it can easily be modified as needed by the...
|
by: Jeff Cooper |
last post by:
Hey Folks,
I have a bunch of aspx pages in a solution. One of these pages, call it
header1.aspx, has it's code behind in header1.aspx.vb. Another,
header2.aspx, has header2.aspx.vb. When I...
|
by: martin |
last post by:
Hi,
I am a web page and a web user control. My web user control is placed in my
web page using the following directive
<%@ Register TagPrefix="uc1" TagName="Header"...
|
by: Invalidlastname |
last post by:
Hi,
I just read the pattern "Design and Implementation Guidelines for Web
Clients" from MSDN.
Here is my question. In chapter 3,...
|
by: Cliff Cavin |
last post by:
How do I programatically change the background color of an aspx page in
code?
Is there something like Page.BgColor = "#FFFFFF" ?
For that matter, how do I access any of the DOCUMENT...
| |
by: William Parker |
last post by:
I have a web control I made called header.ascx. It has its own properties
and methods I defined. But I cannot figure out how to access this control
from my code behind page.
I can create the...
|
by: N. Demos |
last post by:
I have a user control with code behind of which two instances are
created/declared in my aspx page. The aspx page has code behind also, as
I need to access methods of the usercontrols on page...
|
by: Alan Silver |
last post by:
Hello,
I have installed the 2.0 framework, and am looking at converting some of
my 1.1 pages to use partial classes. I don't (yet) have VS2005, so I'm
doing this by hand, but am having problems....
|
by: Pierre |
last post by:
Hello,
In an aspx page (mypage.aspx) from a web projet,
I would like to get the value of a variable of the projet that is declared
as public in a module.
The variable can be called from...
|
by: Yourself |
last post by:
Is there anyway of processing an ASP.NET page after the code behind has run,
but before it's presented as HTML?
What I'm trying to do is alter some of the markup that a content management
system...
|
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,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
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...
| |
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 ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |