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.SqlClient.SqlConnection.OnError(SqlExc eption exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader( CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNo nQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
Any help would be appreciated.
Thanks,
Sahashra
1 1466
I am unfamiliar with the AddWithValue method so I looked it up.
According to MSDN:
AddWithValue replaces the SqlParameterCollection.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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |