ASP SOURCE CODE
<asp:RadioButtonList ID="Cmpany" runat="server" >
<asp:ListItem Text="IT" Value="1"></asp:ListItem>
<asp:ListItem Text="NON_IT" Value="2"></asp:ListItem>
<asp:ListItem Text="Acedamy" Value="3"></asp:ListItem>
<asp:ListItem Text="Trainee" Value="4"></asp:ListItem>
</asp:RadioButtonList>
C#
String name="";
string CONS="";
CONS=System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
name=Cmpany.SelectedItem.Text;
SQlConnection con= new SqlConnection(CONS);
Sqlcommand cmmd=new SqlCommand("Sp_CompanyDepatr", con);
cmmd.CommandType = CommandType.StoredProcedure;
cmmd.Parameters.AddWithValue("@name", name);
con.open();
Sqldataadapter Adp= new SqlDataAdapter(cmmd);
cmmd.ExecuteNonQuery();
Sp_CompanyDepatr CREATE PROCEDURE Sp_CompanyDepatr
@name varchar(50)
as
begin
insert into Table_1 (dept) values(@name)
end
It seems to be some where in forum reply...
Self-Innovator
I used in My Project...
Which Forums....
Any way dotnet Starters will Get Benefit
In dotnetfunda Forums K...How do u pass the value wil u pls rectify and ur code is not working...Kindly chek it before posting
cmmd.Parameters.AddWithValue("@name", name);
Self-Innovator:
Now i updated Code , plz check it
in that name is a string...
So we are going to pass parameter name to sp;
in that name we are getting selected index text to insert into the database...
Sorry mahesh still not wrking....kindly run in your System once and then Post it... Will u pls Explain where u you are getting the ConnectionString...
SQlConnection con= new SqlConnection(CONS);
i think ur Sqlconnection is the problem.
Please do it:
Write it in Web.config flie
Web.config
<connectionStrings>
<add name="ConnectionString" connectionString="ur connection string" />
</connectionStrings>
Call it in C#
C#
string CONS="";
CONS=System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
Sorry thats not an Error Con.open() statement reqd needs to open the Connection so that commad will get Execute...Chek this now it will work So run in your System before posting it..
String name="";
name=Cmpany.SelectedItem.Text;
SQlConnection con= new SqlConnection(CONS);
Sqlcommand cmmd=new SqlCommand("Sp_CompanyDepatr", con);
cmmd.CommandType = CommandType.StoredProcedure;
cmmd.Parameters.AddWithValue("@name", name);
con.open();
Sqldataadapter Adp= new SqlDataAdapter(cmmd);
cmmd.ExecuteNonQuery();
String name="";
string CONS="";
CONS=System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
name=Cmpany.SelectedItem.Text;
SQlConnection con= new SqlConnection(CONS);
Sqlcommand cmmd=new SqlCommand("Sp_CompanyDepatr", con);
cmmd.CommandType = CommandType.StoredProcedure;
cmmd.Parameters.AddWithValue("@name", name);
con.open();
Sqldataadapter Adp= new SqlDataAdapter(cmmd);
cmmd.ExecuteNonQuery();
Now its Working
Yes tats wat u need to Chek it Once before posting it...without opening the state of Connection it will throw an exception....