Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts

Wednesday, March 21, 2012

hi, i need help on SQL, thanks


I'm doing a shopping cart using SQL Express and Visual Studio Web Developer on C#, ASP.NET

I recieved error when adding a order:

The variable name '@.oid' has already been declared. Variable names must be unique within a query batch or stored procedure.


The codes are:
comm = new SqlCommand("SELECT IDENT_CURRENT('Orders') as NewOrderID ");

comm.Connection = conn;
comm.Transaction = myTrans;

OrderID = Convert.ToInt32(comm.ExecuteScalar());

foreach (CartItem i in o.ItemList)
{
comm.CommandText = "INSERT INTO OrderDetail(OrderID, ProductID,Quantity, UnitPrice)VALUES (@.oid, @.pid, @.qty, @.price)";

comm.Parameters.AddWithValue("@.oid", OrderID);
comm.Parameters.AddWithValue("@.pid", i.ProductID);
comm.Parameters.AddWithValue("@.qty", i.Quantity);
comm.Parameters.AddWithValue("@.price", i.UnitPrice);
comm.Connection = conn;
comm.Transaction = myTrans;
comm.ExecuteNonQuery();
}

It seems that i can't add records into database with multiple loop.

Thanks in advance.

Well you want to only call once the insert for multiple items, that will optimize the code a little bit more.

Use TableAdapters, On the project right click and select Add New Item, select a DataSet and create a method to add multiple items!

|||

Try to clear parameters after each insert.

Add this to the end of your code block:

...........

comm.ExecuteNonQuery();

comm.Parameters.Clear();

}

|||

Thanksalbertpascual,

I'm not sure about using a TableAdapter, but does declaring the parameters outside the loop works?

I tried adding a dataset but with my limited 1month knowledge, I don't know how to complete the wizard or codes for the dataset.

if changing my existing codes works, it will be great.

thanks again,

|||

Hey, thanks alot Limno!!

but adding this sweet and simple "comm.Parameters.Clear();" it works..

thanks!!

Friday, March 9, 2012

help-how to retrive date from sql to array

i m new 4 asp.net

i retrive data from sql database.
now,
i want to put that retrived data into array.
how could i do this?

i am use vb.net

plz anyone give any idea.
it's urgent

thanks in advance.U shud be able to do that using a foreach loop for going thru each DataRow in all the existing rows and then add the field values to an ArrayList. something like below..its a very rough outline but I guess it wud help u get a direction. I may be able to help u better if u can revert back with what exactly u are trying to do.


ArrayList ar = new ArrayList();
foreach (DataRow dr in yourtable.Rows)
{
ar.Add(dr.Columns["yourfield"]);
}

hth

help-for copying database

hi,
i m new 4 sql server.
i create one app. in asp.net.

i create one database in sql server.
now,
i want to make setup for my app.
so,
i want copy database and put on c:/.../wwwroot/app folder.

how can i do this?

one more things,
i create database using enterprise manager.
i want to see my database file.
where it is stored?

somebody help me.

it's urgent.
thanks in advance.Not a wise move but if you insist, right-click on the database from Ent Mgr and then click on the Data Files tab, you will find the path to your datbase file there. Next, click on the Transaction Log tab on you will find the path to your transaction log there; these are the two files that make an SQL database.

Wednesday, March 7, 2012

Help; ASP web site, IIS 6.0, Server 2003, SQL server 2000

Hi
I,m new to Server 2003 and I'm moving an ASP website to it.
This is what I have; an basic ASP web site that connects to a "SQL server
2000" database on Windows XP box, using IIS.
Now I have moved the site to Server 2003, on IIS 6, but I'm still using "SQL
Server 2000"
However I can't get the website to connect to the database. this is the
error I'm am geting
Microsoft OLE DB Provider for SQL Server error '80004005'
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access
denied.
/uoc/include/Common.asp, line 100
In IIS 6.0, under the Directory Security tab, I'm using anonymous access,
and it uses the user IUSR_<computername>. Also I have Integrated Windows
authentication checked off. Is there some security setting that I need to
set, or do I need to give more access to the "IUSR" user? (oh and I also
confirmed that SQL server is using SQL Server and Windows Authentication )
Thanks for any help you can give me.
http://spaces.msn.com/members/anthonyarms/
is there an OLEDB connection string in that Common.asp page? it sounds
like thats your connection string. you may need to modify it
accordingly.
|||Thanks for the reply
My connection looks like this :
Application("Connection_ConnectionString") = "Provider=SQLOLEDB.1;Persist
Security Info=False;User ID=[database_name];Initial Catalog=UOC;Data
Source=[computer_name];Use Procedure for Prepare=1;Auto Translate=True;Packet
Size=4096;Workstation ID=[computer_name];Use Encryption for Data=False;Tag
with column collation when possible=False;User
Id=[user_name];PASSWORD=[password];"
I don't know if I need to change anything on Server 2003 (the only things I
changed is the text in the square brackets )
Do you think it could be something else?
thanks for any incite you can provide
http://spaces.msn.com/members/anthonyarms/
"GlennThomas5" wrote:

> is there an OLEDB connection string in that Common.asp page? it sounds
> like thats your connection string. you may need to modify it
> accordingly.
>

Help; ASP web site, IIS 6.0, Server 2003, SQL server 2000

Hi
I,m new to Server 2003 and I'm moving an ASP website to it.
This is what I have; an basic ASP web site that connects to a "SQL server
2000" database on Windows XP box, using IIS.
Now I have moved the site to Server 2003, on IIS 6, but I'm still using "SQL
Server 2000"
However I can't get the website to connect to the database. this is the
error I'm am geting
Microsoft OLE DB Provider for SQL Server error '80004005'
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or
access
denied.
/uoc/include/Common.asp, line 100
In IIS 6.0, under the Directory Security tab, I'm using anonymous access,
and it uses the user IUSR_<computername>. Also I have Integrated Windows
authentication checked off. Is there some security setting that I need to
set, or do I need to give more access to the "IUSR" user? (oh and I also
confirmed that SQL server is using SQL Server and Windows Authentication )
Thanks for any help you can give me.
--
http://spaces.msn.com/members/anthonyarms/Try adding a SQL Server UID and PWD to the connection string.
"ARMS" <anthonyarms@.gmail.com> wrote in message
news:289D8794-31E0-4F67-BC55-F07E18A0875C@.microsoft.com...
> Hi
> I,m new to Server 2003 and I'm moving an ASP website to it.
> This is what I have; an basic ASP web site that connects to a "SQL server
> 2000" database on Windows XP box, using IIS.
> Now I have moved the site to Server 2003, on IIS 6, but I'm still using
"SQL
> Server 2000"
> However I can't get the website to connect to the database. this is the
> error I'm am geting
> Microsoft OLE DB Provider for SQL Server error '80004005'
> [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist o
r access
> denied.
> /uoc/include/Common.asp, line 100
> In IIS 6.0, under the Directory Security tab, I'm using anonymous access,
> and it uses the user IUSR_<computername>. Also I have Integrated Windows
> authentication checked off. Is there some security setting that I need to
> set, or do I need to give more access to the "IUSR" user? (oh and I also
> confirmed that SQL server is using SQL Server and Windows Authentication )
> Thanks for any help you can give me.
> --
> http://spaces.msn.com/members/anthonyarms/

Help; ASP web site, IIS 6.0, Server 2003, SQL server 2000

Hi
I,m new to Server 2003 and I'm moving an ASP website to it.
This is what I have; an basic ASP web site that connects to a "SQL server
2000" database on Windows XP box, using IIS.
Now I have moved the site to Server 2003, on IIS 6, but I'm still using "SQL
Server 2000"
However I can't get the website to connect to the database. this is the
error I'm am geting
Microsoft OLE DB Provider for SQL Server error '80004005'
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access
denied.
/uoc/include/Common.asp, line 100
In IIS 6.0, under the Directory Security tab, I'm using anonymous access,
and it uses the user IUSR_<computername>. Also I have Integrated Windows
authentication checked off. Is there some security setting that I need to
set, or do I need to give more access to the "IUSR" user? (oh and I also
confirmed that SQL server is using SQL Server and Windows Authentication )
Thanks for any help you can give me.
http://spaces.msn.com/members/anthonyarms/
Try adding a SQL Server UID and PWD to the connection string.
"ARMS" <anthonyarms@.gmail.com> wrote in message
news:289D8794-31E0-4F67-BC55-F07E18A0875C@.microsoft.com...
> Hi
> I,m new to Server 2003 and I'm moving an ASP website to it.
> This is what I have; an basic ASP web site that connects to a "SQL server
> 2000" database on Windows XP box, using IIS.
> Now I have moved the site to Server 2003, on IIS 6, but I'm still using
"SQL
> Server 2000"
> However I can't get the website to connect to the database. this is the
> error I'm am geting
> Microsoft OLE DB Provider for SQL Server error '80004005'
> [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access
> denied.
> /uoc/include/Common.asp, line 100
> In IIS 6.0, under the Directory Security tab, I'm using anonymous access,
> and it uses the user IUSR_<computername>. Also I have Integrated Windows
> authentication checked off. Is there some security setting that I need to
> set, or do I need to give more access to the "IUSR" user? (oh and I also
> confirmed that SQL server is using SQL Server and Windows Authentication )
> Thanks for any help you can give me.
> --
> http://spaces.msn.com/members/anthonyarms/

Help; ASP web site, IIS 6.0, Server 2003, SQL server 2000

Hi
I,m new to Server 2003 and I'm moving an ASP website to it.
This is what I have; an basic ASP web site that connects to a "SQL server
2000" database on Windows XP box, using IIS.
Now I have moved the site to Server 2003, on IIS 6, but I'm still using "SQL
Server 2000"
However I can't get the website to connect to the database. this is the
error I'm am geting
Microsoft OLE DB Provider for SQL Server error '80004005'
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or
access
denied.
/uoc/include/Common.asp, line 100
In IIS 6.0, under the Directory Security tab, I'm using anonymous access,
and it uses the user IUSR_<computername>. Also I have Integrated Windows
authentication checked off. Is there some security setting that I need to
set, or do I need to give more access to the "IUSR" user? (oh and I also
confirmed that SQL server is using SQL Server and Windows Authentication )
Thanks for any help you can give me.
--
http://spaces.msn.com/members/anthonyarms/is there an OLEDB connection string in that Common.asp page? it sounds
like thats your connection string. you may need to modify it
accordingly.|||Thanks for the reply
My connection looks like this :
Application("Connection_ConnectionString") = "Provider=SQLOLEDB.1;Persist
Security Info=False;User ID=[database_name];Initial Catalog=UOC;Data
Source=[computer_name];Use Procedure for Prepare=1;Auto Translate=True;P
acket
Size=4096;Workstation ID=[computer_name];Use Encryption for Data=False;T
ag
with column collation when possible=False;User
Id=[user_name];PASSWORD=[password];"
I don't know if I need to change anything on Server 2003 (the only things I
changed is the text in the square brackets )
Do you think it could be something else?
thanks for any incite you can provide
--
http://spaces.msn.com/members/anthonyarms/
"GlennThomas5" wrote:

> is there an OLEDB connection string in that Common.asp page? it sounds
> like thats your connection string. you may need to modify it
> accordingly.
>

Help; ASP web site, IIS 6.0, Server 2003, SQL server 2000

Hi
I,m new to Server 2003 and I'm moving an ASP website to it.
This is what I have; an basic ASP web site that connects to a "SQL server
2000" database on Windows XP box, using IIS.
Now I have moved the site to Server 2003, on IIS 6, but I'm still using "SQL
Server 2000"
However I can't get the website to connect to the database. this is the
error I'm am geting
Microsoft OLE DB Provider for SQL Server error '80004005'
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access
denied.
/uoc/include/Common.asp, line 100
In IIS 6.0, under the Directory Security tab, I'm using anonymous access,
and it uses the user IUSR_<computername>. Also I have Integrated Windows
authentication checked off. Is there some security setting that I need to
set, or do I need to give more access to the "IUSR" user? (oh and I also
confirmed that SQL server is using SQL Server and Windows Authentication )
Thanks for any help you can give me.
--
http://spaces.msn.com/members/anthonyarms/is there an OLEDB connection string in that Common.asp page? it sounds
like thats your connection string. you may need to modify it
accordingly.|||Thanks for the reply
My connection looks like this :
Application("Connection_ConnectionString") = "Provider=SQLOLEDB.1;Persist
Security Info=False;User ID=[database_name];Initial Catalog=UOC;Data
Source=[computer_name];Use Procedure for Prepare=1;Auto Translate=True;Packet
Size=4096;Workstation ID=[computer_name];Use Encryption for Data=False;Tag
with column collation when possible=False;User
Id=[user_name];PASSWORD=[password];"
I don't know if I need to change anything on Server 2003 (the only things I
changed is the text in the square brackets )
Do you think it could be something else?
thanks for any incite you can provide
--
http://spaces.msn.com/members/anthonyarms/
"GlennThomas5" wrote:
> is there an OLEDB connection string in that Common.asp page? it sounds
> like thats your connection string. you may need to modify it
> accordingly.
>

Sunday, February 19, 2012

HELP: ASP.NET won''t connect to SQLexpress after deploying to IIS, try a lot of things...

Hello,

I have finish building my ASP.NET site using VS 2005 and it compile just fine. Than I try hosting it to the web via IIS v5.1 and I am getting permission error from SQL express.

I have posted a detail question in experts-exchange.com and since you need a user account to even view the thread, I have taken the liberty to save the thread as .html file and host it to my ISP site. You can see the detail problem I am having here: http://users.accesscomm.ca/mm/EEdetail.html

I am going to list out some stuff I have done:

1. I have two database that need access, the ASPNETDB.mdf for user login and another database (PhotoDataBase.mdf) to store information relating to the photo I uploaded to my ASP.NET site.

2. I have already follow this How to site: http://blogs.msdn.com/sqlexpress/archive/2005/05/05/415084.aspx and setup:
- TCP/IP enable, as shown here:
- I have started SQL Browser service
- The firewall part I am not so sure about. I am currently using Zonealarm....

3. I have installed SQL Server Management Studio Express(SSMSE) and attach the two database to it.

4. I have set SSMSE server properties to accept both SQL and window authentication.

5. I have made sure that both database "read only" setting to false

6. I have setup SQL login with User ID = SQLLOGIN

Here is the original connection in web.config:
<add name="ConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|Da

taDirectory|\PhotoDataBase.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />

and here is the new connection I just type in web.config that replace the original one:
<add name="ConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PhotoDataBase.mdf; Server=MINGDESKTOP; Integrated Security=False; uid=SQLLOGIN; Password=XXXXXX;"
providerName="System.Data.SqlClient" />

and the error i get are the follow:

Server Error in '/' Application.
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

7. I did haven't done much to ASPNETDB.mdf yet and the error i get right now are the following:

_

___
Server Error in '/' Application.
Cannot open user default database. Login failed.
Login failed for user 'MINGDESKTOP\ASPNET'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot open user default database. Login failed.
Login failed for user 'MINGDESKTOP\ASPNET'.
__

Please help! I am really running out of ideas.... and I need to have this setup in a few days....

Thanks!

These two links will take you in the right direction but you still have the ASPNETDB as a User Instance database which is not supported in other editions of SQL Server so you need to correct that also. In Asp.net deployment takes careful planning or any part of the application can stop the deployment. Hope this helps.

http://geekswithblogs.net/ranganh/archive/2005/04/25/37613.aspx

http://weblogs.asp.net/scottgu/archive/2006/04/22/Always-set-the-_2200_applicationName_2200_-property-when-configuring-ASP.NET-2.0-Membership-and-other-Providers.aspx

|||

Caddre wrote:

These two links will take you in the right direction but you still have the ASPNETDB as a User Instance database which is not supported in other editions of SQL Server so you need to correct that also. In Asp.net deployment takes careful planning or any part of the application can stop the deployment. Hope this helps.

http://geekswithblogs.net/ranganh/archive/2005/04/25/37613.aspx

http://weblogs.asp.net/scottgu/archive/2006/04/22/Always-set-the-_2200_applicationName_2200_-property-when-configuring-ASP.NET-2.0-Membership-and-other-Providers.aspx

Thanks! This is the answer I needed!

|||

I am glad I could help.

Help: Append Parameters in ASP classic

Hi,

Please tell me what is wrong in the following code to get the RecordSet by calling the Stored Procedure.

'==============================================
Dim StaffRS, objComm, objParam1, objParam2, objParam3

'Set RecordSet, ADODB.Command
Set StaffRs = Server.CreateObject("ADODB.RECORDSET")
Set objComm = Server.CreateObject("ADODB.Command")
objComm.ActiveConnection = conn 'conn was set earler
objComm.CommandText = "GetStaffReport" 'Stored Procedure
objComm.CommandType = adCmdStoredProc '**Error line**

'Append Parameters
set objParam1 = objcomm.CreateParameter ("People_ID", adVarChar, adParamInput, "123")
objComm.Parameters.Append objparam1
set objparam2 = objcomm.CreateParameter ("DateLow", adDate, adParamInput, 02/02/2006)
objComm.Parameters.Append objparam2
set objparam3 = objcomm.CreateParameter ("DateHigh", adDate, adParamInput, 02/15/2006)
objComm.Parameters.Append objparam3

set StaffRS = objComm.Execute
'Close up work...
'============================================

The Stored Procedure is:
'********************************************
CREATE PROCEDURE GetStaffReport
(@.People_ID varchar(32), @.Weeklow datetime, @.Weekhigh datetime)

AS

SELECT * FROM view_People WHERE
Main_People = @.People_ID AND Main_Ending >= @.WeekLow AND Main_Ending <= @.Weekhigh
Order by Main_Ending DESC

RETURN
GO
'*********************************************

Everything looks correct, but I got an error:
ADODB.Command error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/folder/folder/file.asp, line (**Error line**)

Please give me any information about this error, and how to correct it.

Thank you.

Looking at your code

set objParam1 = objcomm.CreateParameter ("People_ID", adVarChar, adParamInput, "123")
objComm.Parameters.Append objparam1
set objparam2 = objcomm.CreateParameter ("DateLow", adDate, adParamInput, "02/02/2006")
objComm.Parameters.Append objparam2
set objparam3 = objcomm.CreateParameter ("DateHigh", adDate, adParamInput, "02/15/2006")
objComm.Parameters.Append objparam3

Won't you qoute two parameter values listed above? Without quotes you pass 02 divided by 02 divided by 2006 (very small number) as a value for datetime.

WBR, Evergray
--
Words mean nothing...

|||

Thank you, WBR,

Actually, the "02/02/2006" is what I put here in the forum, there is a real parameter Week1 with a gaven format: Week1= FormatDateTime (WeekEndingLow,2), which is 2/02/2006. The "02/15/2006" is the same way. So the lines in my real code is:

set objParam1 = objcomm.CreateParameter ("People_ID", adVarChar, adParamInput, Staff_ID)
objComm.Parameters.Append objparam1

set objparam2 = objcomm.CreateParameter ("DateLow", adDate, adParamInput, Week1)objComm.Parameters.Append objparam2
set objparam3 = objcomm.CreateParameter ("DateLow", adDate, adParamInput, Week2)objComm.Parameters.Append objparam3

But it still has the error:"800a0bb9"

By the way, the stored procedure I called is reading the data from a view:

"SELECT * FROM view_People" the view_People is a view, not a table, I don't know if this is a problem.

Thank you for your help.

|||

maybe you should do this;

objComm.CommandType = adCmdStoredProc '**Error line**
objComm.CommandType = 4

good luck

Help: Append Parameters in ASP classic

Hi,

Please tell me what is wrong in the following code to get the RecordSet by calling the Stored Procedure.

'==============================================
Dim StaffRS, objComm, objParam1, objParam2, objParam3

'Set RecordSet, ADODB.Command
Set StaffRs = Server.CreateObject("ADODB.RECORDSET")
Set objComm = Server.CreateObject("ADODB.Command")
objComm.ActiveConnection = conn 'conn was set earler
objComm.CommandText = "GetStaffReport" 'Stored Procedure
objComm.CommandType = adCmdStoredProc '**Error line**

'Append Parameters
set objParam1 = objcomm.CreateParameter ("People_ID", adVarChar, adParamInput, "123")
objComm.Parameters.Append objparam1
set objparam2 = objcomm.CreateParameter ("DateLow", adDate, adParamInput, 02/02/2006)
objComm.Parameters.Append objparam2
set objparam3 = objcomm.CreateParameter ("DateHigh", adDate, adParamInput, 02/15/2006)
objComm.Parameters.Append objparam3

set StaffRS = objComm.Execute
'Close up work...
'============================================

The Stored Procedure is:
'********************************************
CREATE PROCEDURE GetStaffReport
(@.People_ID varchar(32), @.Weeklow datetime, @.Weekhigh datetime)

AS

SELECT * FROM view_People WHERE
Main_People = @.People_ID AND Main_Ending >= @.WeekLow AND Main_Ending <= @.Weekhigh
Order by Main_Ending DESC

RETURN
GO
'*********************************************

Everything looks correct, but I got an error:
ADODB.Command error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/folder/folder/file.asp, line (**Error line**)

Please give me any information about this error, and how to correct it.

Thank you.

Looking at your code

set objParam1 = objcomm.CreateParameter ("People_ID", adVarChar, adParamInput, "123")
objComm.Parameters.Append objparam1
set objparam2 = objcomm.CreateParameter ("DateLow", adDate, adParamInput, "02/02/2006")
objComm.Parameters.Append objparam2
set objparam3 = objcomm.CreateParameter ("DateHigh", adDate, adParamInput, "02/15/2006")
objComm.Parameters.Append objparam3

Won't you qoute two parameter values listed above? Without quotes you pass 02 divided by 02 divided by 2006 (very small number) as a value for datetime.

WBR, Evergray
--
Words mean nothing...

|||

Thank you, WBR,

Actually, the "02/02/2006" is what I put here in the forum, there is a real parameter Week1 with a gaven format: Week1= FormatDateTime (WeekEndingLow,2), which is 2/02/2006. The "02/15/2006" is the same way. So the lines in my real code is:

set objParam1 = objcomm.CreateParameter ("People_ID", adVarChar, adParamInput, Staff_ID)
objComm.Parameters.Append objparam1

set objparam2 = objcomm.CreateParameter ("DateLow", adDate, adParamInput, Week1)objComm.Parameters.Append objparam2
set objparam3 = objcomm.CreateParameter ("DateLow", adDate, adParamInput, Week2)objComm.Parameters.Append objparam3

But it still has the error:"800a0bb9"

By the way, the stored procedure I called is reading the data from a view:

"SELECT * FROM view_People" the view_People is a view, not a table, I don't know if this is a problem.

Thank you for your help.

|||

maybe you should do this;

objComm.CommandType = adCmdStoredProc '**Error line**
objComm.CommandType = 4

good luck

Help...pls check whats wrong....not able to do insert with sqldatasource

Hi frdz,

I m the new user of ASP.NET WEB APPLICATIONS WITH C# LANGUAGE.
I m using SQL SERVER 2005 and SQLDATASOURCE to get or retrieve the data from the database.
I have created the stored procedure for insert and update.
The stored procedure is executing fine when i m running it from sqlserver2005.

My problem is with the web-application page.
I m not able to insert or update data thru that...
Pls check the code and tell me what's missing out ........

SQLDATASOURCE

<asp:SqlDataSource ID="srcemp" runat="server" ConnectionString="<%$ ConnectionStrings:empmaster %>"
InsertCommand="empStoredProcedure" InsertCommandType="StoredProcedure"
UpdateCommand="empStoredProcedure" UpdateCommandType="StoredProcedure"
DeleteCommand="DELETE FROM empmaster
WHERE empid = @.empid" DeleteCommandType="Text"
SelectCommand="select * from empmaster " SelectCommandType="Text">
<InsertParameters>
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="address" Type="String" />
<asp:Parameter Name="city" />
<asp:Parameter Name="pincode" />
<asp:Parameter Name="state" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="empname" Type="String" />
<asp:Parameter Name="address" Type="String" />
<asp:Parameter Name="city" />
<asp:Parameter Name="pincode" />
<asp:Parameter Name="state" />
</UpdateParameters>
</asp:SqlDataSource
GRIDVIEW

<asp:GridView ID="empGridView" runat="server" AutoGenerateColumns="False"
DataKeyNames="empid" DataSourceID="srcemp"
Width="56px" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this row ?');">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>


<asp:boundfield datafield="empname"
headertext="emp Name"/>
<asp:boundfield datafield="address"
headertext="Address"/>
<asp:boundfield datafield="city"
headertext="City"/>
<asp:boundfield datafield="state"
headertext="State"/>


<asp:CheckBoxField
DataField="deleted"
HeaderText="In Existance" />

</Columns>

</asp:GridView
C# code

protected void cmdsubmit_Click(object sender, EventArgs e)
{
srcemp.InsertParameters["empname"].DefaultValue = tbcompanyname.Text;
srcemp.InsertParameters["address"].DefaultValue = tbaddress.Text;
srcemp.InsertParameters["city"].DefaultValue = tbcity.Text;
srcemp.InsertParameters["pincode"].DefaultValue = tbpincode.Text;
srcemp.InsertParameters["state"].DefaultValue = cmbstate.SelectedItem.ToString();

srcemp.Insert();
}

Note :

I m not getting a single error msg for the above code in web-page or stored procedure but it does not insert,update or delete the record from the database...
Thanxs in adv...

pls reply at earliest if possible...What's missing ??

can anyone check out..what's wrong ??

Hi,

From your code, it seems that your parameters come from TextBox and DropDownList. So you should try this way:

<asp:SqlDataSource ID="srcemp" runat="server" ConnectionString="<%$ ConnectionStrings:empmaster %>"
InsertCommand="empStoredProcedure" InsertCommandType="StoredProcedure"
UpdateCommand="empStoredProcedure" UpdateCommandType="StoredProcedure"
DeleteCommand="DELETE FROM empmaster
WHERE empid = @.empid" DeleteCommandType="Text"
SelectCommand="select * from empmaster " SelectCommandType="Text">
<InsertParameters>

<asp:ControlParameter Name="empname" ControlId="tbcompanyname" PropertyName="Text"/>
<asp:ControlParameter Name="address" ControlId="tbaddress" PropertyName="Text"/>
<asp:ControlParameter Name="city" ControlId="tbcity" PropertyName="Text"/>
<asp:ControlParameter Name="pincode" ControlId="tbpincode" PropertyName="Text"/>
<asp:ControlParameter Name="state" ControlId="cmbstate" PropertyName="SelectedItem"/>

</InsertParameters>
<UpdateParameters>
<asp:ControlParameter Name="empname" ControlId="tbcompanyname" PropertyName="Text"/>
<asp:ControlParameter Name="address" ControlId="tbaddress" PropertyName="Text"/>
<asp:ControlParameter Name="city" ControlId="tbcity" PropertyName="Text"/>
<asp:ControlParameter Name="pincode" ControlId="tbpincode" PropertyName="Text"/>
<asp:ControlParameter Name="state" ControlId="cmbstate" PropertyName="SelectedItem"/>

</UpdateParameters>
</asp:SqlDataSource>

In your C# code:

protected void cmdsubmit_Click(object sender, EventArgs e)
{
srcemp.Insert();
}

Hope this helps. Thanks.