By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

Unable To Insert The Data With Stored Procedure Using Sqldatasource,gridview

P: 20
Hello Members,

I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005.

What i have used on forms :: ?
On my first form i have used some label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls.
On the click event of the command button the data gets stored into the database.
I have created the stored procedures for the insert,update,delete.
I have used sqldatasource for the connection to server and storing data.
On submit button click event data should be inserted and displayed on the grid.The grid contains the two commandfield show button links on which i
want to perform the edit(update/cancel) and delete for the data which are present in the gridview.



The stored procedure executes correctly on sql-server2005 so there's not at all problem in the stored procedure it must on the button click event code of the C# where something must be missing.
If i write the simple sql insert query in the C# code then there's no problem.It inserts and displays data thru sqldatasoure.So,the problem is with the stored procedure which is used in C#.

No,for ur reference the following 2tables i have used and the control for which i used are written.


SQL 2005 DATABASE TABLE DETAILS


1) employee_table

(PK)Employeeid int(4) NOT NULL (TEXTBOX CONTROL–AUTOGENERATED)
(FK)Locationid int(4)NOT NULL (LABEL CONTROL -- AUTOGENERATED)
Employeename varchar(15)NOT NULL (TEXTBOX CONTROL)
Gender char(6) (RADIOBUTTON CONTROL)
City varchar(15) (DROPDOWNLIST CONTROL)
Joindate datetime (DATEPICKER USED JAVASCRIPT)
Card Issue char(3) (CHECKBOX CONTROL)
Salary money (TEXTBOX CONTROL)

2) location_table

(PK)Locationid int(4)NOT NULL (LABEL CONTROL -- AUTOGENERATED)
Locationname varchar(15)NOT NULL (TEXTBOX CONTROL)



The coding done in C# is as follows...i have pasted only the imp code not the whole page.Please rectify it.

GRIDVIEW

<asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="true"
SelectedRowStyle-CssClass="selectedRow" DataSourceID="SqlDataSource1"
DataKeyNames="employeeid,locationid" >
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
<asp:GridView / >

SQLDATASOURCE

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:employee_table,location_table %>"
ProviderName="System.Data.SqlClient"
InsertCommand="EmpLocationInsertJoin" InsertCommandType="StoredProcedure">

<InsertParameters>
<asp:Parameter Name="employeeid" Direction="Output" />
<asp:Parameter Name="locationid" Direction="Output" />
<asp:Parameter Name="employeename" Type="String" Direction="Input"/>
<asp:Parameter Name="city" Type="String" Direction="Input"/>
<asp:Parameter Name="joindate" Type="Datetime" Direction="Input"/>
<asp:Parameter Name=''salary'' Type="INT16" Direction="Input"/>
<asp:Parameter Name="locationname" Type="String" Direction="Input"/>
</InsertParameters>

</asp:SqlDataSource>

C# SOURCE CODE
protected void Page_Load(object sender, EventArgs e)
{
GridView1.Visible = false;

}

protected void cmdsubmit_Click(object sender, EventArgs e)
{
string employeename = tbemployeename.Text.ToString();
string locationname = tblocationname.Text.ToString();
string salary=tbsalary.Text.ToString();

tbemployeeid.Text=command.Parameters["employeeid"].Value.ToString();
lblocationid.Text=command.Parameters["locationid"].Value.ToString();

SqlDataSource1.InsertParameters[0].DefaultValue = employeename;
SqlDataSource1.InsertParameters[1].DefaultValue = locationname;
SqlDataSource1.InsertParameters[2].DefaultValue = city;
SqlDataSource1.InsertParameters[3].DefaultValue = joindate;
SqlDataSource1.InsertParameters[4].DefaultValue = salary;

---- MISSING CODE NEED HELP ---

SqlDataSource1.Insert();
GridView1.Visible = true;
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridView1.Visible = true;
---- MISSING CODE NEED HELP ---
}

How to specify the checkbox,radiobutton,dropdownlist used and datepicker control the date which selected in textbox should be written in the C# source code on submit click event.I want to also know what should be done in GridView for the edit and delete with stored procedure.
I want everyone's help for where i have written ---- MISSING CODE NEED HELP ---.Also pls if possible then check the whole code.If any mistake then surely please point out.

I try to find thru search engine some help but i was not able to get the proper link.

Please reply at the earliest.Waiting for the replies...

Thanxs
Apr 6 '07 #1
Share this Question
Share on Google+
1 Reply


kenobewan
Expert 2.5K+
P: 4,871
Welcome to the site. If you have your datasource insert parameters properly you should only need to call the insert method. Then you need to refresh the datasource in the second part of code to see new data. Suggest you make these changes, test the code and report back. HTH.
Apr 6 '07 #2

Post your reply

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