473,666 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding records from a textbox (C# Visual Web Developer)

1 New Member
I'm trying to add new records to my database using 4 textboxes, one for each field in my databases table. I've got ID, Firstname, Surname and Course.

But I can't figure out at all how to link whats Inputted into the textboxes to be added as a new record to my database when the "Insert Record" button is pushed.., i've spent nearly 2 hours searching the internet for tutorials and people asking similar questions but I can't find anything that works.

I think the solution might be in this line of code:


InsertCommand=" INSERT INTO [Data1] ([ID], [Firstname], [Surname], [Course]) VALUES ()"



I've tried putting the ID's of my textboses in the "VALUES ()" part..

(e.g. VALUES (ID.Text, Firstname.Text, Surname.Text, Course.Text)


But that doesn't seem to work, I need the values to be what has been inputted into my textboxes, but I'm not sure what the correct way to do that is or what I need to write between the brackets.

My textboxes ID's are ID, Firstname, Surname and Course.





Heres a screenshot of the page, to make it easier to understand what I'm talking about:


Fullcode for the page is:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">





private void InsertRecord(ob ject source, EventArgs e)
{
AccessDataSourc e1.Insert();
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>


<asp:TextBox ID="ID" runat="server"> </asp:TextBox>
<asp:TextBox ID="Firstname" runat="server"> </asp:TextBox>
<asp:Button ID="btnInsertRe cord" runat="server" Style="z-index: 100; left: 273px;
position: absolute; top: 102px" Text="Insert Record" OnClick="Insert Record" Width="117px" />
<asp:TextBox ID="Surname" runat="server"> </asp:TextBox>
<asp:TextBox ID="Course" runat="server"> </asp:TextBox>






<asp:AccessData Source ID="AccessDataS ource1" runat="server" DataFile="~/App_Data/unidata.mdb"
DeleteCommand=" DELETE FROM [Data1] WHERE [ID] = ?" InsertCommand=" INSERT INTO [Data1] ([ID], [Firstname], [Surname], [Course]) VALUES ()"
SelectCommand=" SELECT * FROM [Data1]" UpdateCommand=" UPDATE [Data1] SET [Firstname] = ?, [Surname] = ?, [Course] = ? WHERE [ID] = ?">
<DeleteParamete rs>
<asp:Paramete r Name="ID" Type="String" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="Firstname " Type="String" />
<asp:Paramete r Name="Surname" Type="String" />
<asp:Paramete r Name="Course" Type="String" />
<asp:Paramete r Name="ID" Type="String" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="ID" Type="String" />
<asp:Paramete r Name="Firstname " Type="String" />
<asp:Paramete r Name="Surname" Type="String" />
<asp:Paramete r Name="Course" Type="String" />
</InsertParameter s>
</asp:AccessDataS ource>

</div>

</form>
</body>
</html>
Mar 21 '08 #1
1 2116
Scott Price
1,384 Recognized Expert Top Contributor
Moved to the .NET forum as this is outside the scope of Access experts.

MODERATOR
Mar 22 '08 #2

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

Similar topics

6
2404
by: Jamie Fryatt | last post by:
Hi everyone, here's what id like to do. I have a table with 2 fields, name and value I need to be able to add multiple records quickly, for example I need to add name value abc 1 abc 2 abc 3
4
409
by: Manish Sawjiani | last post by:
Hi Experts, I am just into dot net and i want simple code for adding records into Access table (97) using oledb. There are no queries in the databases and there is only one table: Friends with the following fields: FriendID (AutoNumber) FirstName, LastName and DateOfBirth Please I have tried everything. WOULD BE HIGHLY OBLIGED for HELP Thanks all
8
2081
by: k | last post by:
Hi all I split a database in a table-part and a all-the-rest-part and linked the tables, but my code adding records to a table crashes on Set rs = db.OpenRecordset("tblDeltakelse", dbOpenTable, dbAppendOnly) I think, some places where I do the same thing to another table it just says "Invalid Operation", I press OK and nothing happens, and I am just
0
2087
by: brijeshmathew | last post by:
Hi I use Visual Basic 6, Service Pack 6, Microsoft ActiveX Data Objects 2.8 Library(msado15.dll) and access 2000 database using JET 4 OLE. I have an application that adds records simultaneously to the same table. During the simultaneous add and update, a Locked error occurs, and most of the times it locks all the machines. I have been reading on Microsoft Site and on google groups that JET4 and ADO have fix for page locking , which...
1
1122
by: Nkagi | last post by:
Hi All, I have a problem of adding records into table, if the cursor is on the first record the record that I add replaces the first record and then I moved it to the last record and the new record replaces that last record in the table. Is there a method that I can use to make sure this doesn't happen. The thing is my program was working fine until recently, as I have about 197 records in that table. Can someone please rescue me. this...
0
1152
by: Mustang97 | last post by:
I've created a custom datagrid with a custom ado connection. Everything works perfectly except now I am trying to add a button that will add records. The way I know how to do that is with the commands dim newdatarow as system.data.datarow newdatarow = <dataset.name>.<table.name>.newrow I put in.. newdatarow = db_ds.tbl_movdb.newrow
1
1430
by: slinky | last post by:
On My Webserver I have an Access Database called "Warehouse.mdb" I have a webform that has: 6 Textboxes named: txtAsset_Number.Text, txtDescription.Text, txtSerial_Number.Text, txtMfg.Text, txtRDCnumber.Text, txtAssetType.Text 1 Button named btnAdd
1
1341
by: nitdesh | last post by:
Hi , I have Just Registered to This Site and Deeply Require a Help For my Software . I am Into Warehousing Business I Have Front End as Visual Basic 6.0 and Backend as SQl 7.0 Database Name : deshmukhwarehousing Within Which I have table as GR : Good Recived
1
1498
by: Kristilee | last post by:
I am working with an attendance database that holds records for each employee for when they are absent. For every 30 days WORKED for each employee I need to have the database automatically add a record. (it's an overly complicated attendance policy) Can this be done with a query and SQL or will I have to code in VBA? I am not super proficient in this so any detailed help would be great. I know the syntax for adding records but am not sure...
0
8444
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8869
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5664
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1775
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.