I am trying to insert values into the table using the values from the form
I following is the code I am using -
protected void Button_Click(object sender, EventArgs e)
-
{
-
SqlConnection conn = new SqlConnection("Data Source=.\\SQLExpress;Initial Catalog=MyFavs;Integrated Security=SSPI");
-
-
string insertstring = @"Insert into MyFavs values (@FirstName,@LastName,@Address,@City,@State,@Phone,@Email,@Password)";
-
SqlCommand cmd = new SqlCommand(insertstring, conn);
-
-
cmd.Parameters.AddWithValue("@FirstName", SqlDbType.VarChar).Value = FirstNameTextBox.Text.ToString();
-
cmd.Parameters.AddWithValue("@LastName", SqlDbType.VarChar).Value = LastNameTextBox.Text.ToString();
-
cmd.Parameters.AddWithValue("@Address", SqlDbType.VarChar).Value = AddressTextBox.Text.ToString();
-
cmd.Parameters.AddWithValue("@City", SqlDbType.VarChar).Value = CityTextBox.Text.ToString();
-
cmd.Parameters.AddWithValue("@State", SqlDbType.VarChar).Value = StateTextBox.Text.ToString();
-
cmd.Parameters.AddWithValue("@Phone", SqlDbType.VarChar).Value = PhoneTextBox.Text.ToString();
-
cmd.Parameters.AddWithValue("@Email", SqlDbType.VarChar).Value = EmailTextBox.Text.ToString();
-
cmd.Parameters.AddWithValue("@Password", SqlDbType.VarChar).Value = PasswordTextBox.Text.ToString();
-
-
try
-
{
-
conn.Open();
-
cmd.ExecuteNonQuery();
-
}
-
catch (SqlException er)
-
{
-
Response.Write(er.StackTrace);
-
}
-
finally
-
{
-
conn.Close();
-
}
I get the following error when I execute the code at System.Data.Sql Client.SqlConne ction.OnError(S qlException exception, Boolean breakConnection ) at System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion exception, Boolean breakConnection ) at System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct stateObj) at System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleR esultSet bulkCopyHandler , TdsParserStateO bject stateObj) at System.Data.Sql Client.SqlComma nd.FinishExecut eReader(SqlData Reader ds, RunBehavior runBehavior, String resetOptionsStr ing) at System.Data.Sql Client.SqlComma nd.RunExecuteRe aderTds(Command Behavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.Sql Client.SqlComma nd.RunExecuteRe ader(CommandBeh avior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe) at System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery()
Any help would be appreciated.
Thanks,
Sahashra
1 1483 Frinavale 9,735
Recognized Expert Moderator Expert
I am unfamiliar with the AddWithValue method so I looked it up.
According to MSDN:
AddWithValue replaces the SqlParameterCol lection.Add method that takes a String and an Object.
You are not passing it an Object, you are passing it Strings (text from the TextBox).
I recommend that you use the Add Method instead of the AddWithValue method since you are using strings.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Patrice FRITSCH |
last post by:
I'm trying to run a batch file from an asp page using WScript.Shell object.
Dim oWSH
set oWSH= Server.CreateObject("WScript.Shell")
call oWSH.Run("cmd.exe /c " & szCmd , 0, true)
szCmd contains the program to execute (fop.bat with several parameters).
But I'm getting the following error message :
|
by: Marina Anufreichik |
last post by:
Hi,
After deploymnet web application on web server I can access page on local
machine and login fine but when I'm trying to access web site from remote
machine I can see login page, but when I'm trying to login with correct
credentials it give me error:
Server Error in '/PDVMgr' Application.
----------------------------------------------------------------------------
|
by: Del |
last post by:
We have a MS SQL Server 2000 application for our shipping system. We
have created a front end application using MS Access for our order
analyst. The front end application allows the analyst to review and
update orders before they are released to the warehouse. We are in the
test phase of this project and have run into a couple problems that we
just can not figure out.
During the testing phase there is only one person working in the...
|
by: astro |
last post by:
Anyone have suggestions on where to troubleshoot this error?
Background:
-Access 2k v. 9.0.6926 sp3
- front and backend on production server (wiindows 2k)
-accessed via Citrix
-front-end is mde, backend is mdb
-only occurs on the production server
-only occurs with mde verson - i've tested the problem with the mdb version
of the front-end and it loads/generates the document fine on the production
|
by: Razak |
last post by:
Hi,
I have a class which basically do Impersonation in my web application. From
MS KB sample:-
++++++++++++++++++++code starts
Dim impersonationContext As
System.Security.Principal.WindowsImpersonationContext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
| |
by: Tim D |
last post by:
Hi,
I originally posted this as a reply to a rather old thread in
dotnet.framework.general and didn't get any response. I thought it might be
more relevant here; anyone got any ideas? My questions are below...
"David Good" wrote:
> We have a network running both Win2k and Win2k3 webservers and our web sites
> reside on a UNC network share that happens to be a Network Appliance NAS.
|
by: Gianfranco |
last post by:
Hi everybody,
First of all, sorry for my english if it isn't perfect ;-p
I have an error in an asp.net application.
I have win2003 server, with iis 6. I'm developping with visual studio
2005, vb.net, framework 2
I'm trying to access some binary files stored in C: in server2003. if i
|
by: snicks |
last post by:
I'm trying to exec a program external to my ASP.NET app using the following
code. The external app is a VB.NET application.
Dim sPPTOut As String
sPPTOut = MDEPDirStr + sID + ".ppt"
Dim p As New System.Diagnostics.Process
'p.Start(MDEPDirStr & "macrun.exe", sPPTOut)
p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE")
'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
|
by: deathtospam |
last post by:
A day or two ago, I wrote a quick ASPX page with a CS codebehind using
Visual Studio .NET 2005 -- it worked, I saved it and closed the
project. Today, I came back to the project, reopened the solution, and
was greeted with the following error:
========================================================================
It is an error to use a section registered as
allowDefinition='MachineToApplication' beyond application level. This
error...
|
by: gary0gilbert |
last post by:
An unusual spin to this recurring disk or network error in a Terminal
Server environment. Access 2000, Terminal Server 2000, file server is
windows 2000. All users have a separate copy of the front end db,
everyone accesses the back-end db via a network share. To preface,
non Terminal Server users (4 or 5 in office) never have this problem.
There are two Terminal Servers running win 2000, both basically
identical. This error affects...
|
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...
| |
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...
|
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,...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |