473,803 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error while trying to access the sql server

1 New Member
I am trying to insert values into the table using the values from the form

I following is the code I am using
Expand|Select|Wrap|Line Numbers
  1. protected void Button_Click(object sender, EventArgs e)
  2. {
  3.     SqlConnection conn = new SqlConnection("Data Source=.\\SQLExpress;Initial Catalog=MyFavs;Integrated Security=SSPI");
  4.  
  5.     string insertstring = @"Insert into MyFavs values (@FirstName,@LastName,@Address,@City,@State,@Phone,@Email,@Password)";
  6.     SqlCommand cmd = new SqlCommand(insertstring, conn);       
  7.  
  8.     cmd.Parameters.AddWithValue("@FirstName", SqlDbType.VarChar).Value = FirstNameTextBox.Text.ToString();
  9.     cmd.Parameters.AddWithValue("@LastName", SqlDbType.VarChar).Value = LastNameTextBox.Text.ToString();
  10.     cmd.Parameters.AddWithValue("@Address", SqlDbType.VarChar).Value = AddressTextBox.Text.ToString();
  11.     cmd.Parameters.AddWithValue("@City", SqlDbType.VarChar).Value = CityTextBox.Text.ToString();
  12.     cmd.Parameters.AddWithValue("@State", SqlDbType.VarChar).Value = StateTextBox.Text.ToString();
  13.     cmd.Parameters.AddWithValue("@Phone", SqlDbType.VarChar).Value = PhoneTextBox.Text.ToString();
  14.     cmd.Parameters.AddWithValue("@Email", SqlDbType.VarChar).Value = EmailTextBox.Text.ToString();
  15.     cmd.Parameters.AddWithValue("@Password", SqlDbType.VarChar).Value = PasswordTextBox.Text.ToString();
  16.  
  17.     try
  18.     {
  19.         conn.Open();
  20.         cmd.ExecuteNonQuery();
  21.     }
  22.     catch (SqlException er)
  23.     {
  24.         Response.Write(er.StackTrace);
  25.     }
  26.     finally
  27.     {
  28.         conn.Close();
  29.     }
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
Jun 11 '09 #1
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.
Jun 16 '09 #2

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

Similar topics

5
7044
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 :
9
3008
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. ----------------------------------------------------------------------------
1
2808
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...
7
7241
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
8
9480
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
9
3218
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.
14
9385
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
5
3649
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)
23
5144
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...
10
6167
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...
0
10542
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
10309
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
10289
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
10068
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
9119
agi2029
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...
0
6840
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
5496
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
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
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

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.