ADO/ADO.NET - how to store 4000-6000 kind of value in sqlserver
Asked By mani
10-Mar-11 01:53 AM
hi i have range column as nvarchar..
and i have my code is
string range = cmbrate.SelectedValue.ToString();
and adding like...
comm.Parameters.AddWithValue("@Range", range );
but its atored as 0(zero) only.. how to solve these..
Ritu Rani replied to mani
Hi,
please check your parametername and column name.it may be missppelled.
mani replied to Ritu Rani
ths is my code..and column name in databse as Range..
string range = cmbrate.SelectedValue.ToString();
decimal percentage = Convert.ToDecimal(txtpercentage.Text);
SqlConnection con =
new SqlConnection("server=PERFORMA-18ACD7;Initial Catalog=A4;integrated security=true");
SqlCommand comm =
new SqlCommand("insert into marketprofit_morgin(Range,percentage)values(@Range,@percentage)", con);
comm.Parameters.AddWithValue("@Range", range );
comm.Parameters.AddWithValue("@percentage", percentage);
con.Open();
comm.ExecuteNonQuery();
label10.Text = "Range has been Fixxed";
con.Close();
Vivek Jagga replied to mani
Hi,
Please check your stored procedure variavle name and variable type with its length.
Venu K replied to mani
Hi mani,
You might have created the range Column in SQL Server with datatype nvarchar default set to 0,Have u specified any column width for this column like nvarchar(10) for example
Here is the sample which is working perfectly
string connstring="Integrated Security=SSPI;Initial Catalog=test;Data Source=sl7test1";
using(SqlConnection con=new SqlConnection(connstring))
{
con.Open();
string query="insert into table1 values(@id,@range)";
using (SqlCommand com = new SqlCommand(query, con))
{
com.Parameters.AddWithValue("@id", 3);
com.Parameters.AddWithValue("@range", "4000-5000");
int result=com.ExecuteNonQuery();
Console.Write(result);
}
}
Here is the resultant output of that table
1 2-3
2 40-50
3 4000-5000
Please let me know if you have any queries
Subhashini Janakiraman replied to mani
Here is my code for your query.Hope it helps...
string[] ranges = cmbrate.SelectedValue.ToString().Split('-');
comm.Parameters.AddWithValue("@Rangefrom",ranges[0]);
comm.Parameters.AddWithValue("@Rangeto,ranges[1]);
(or) simply like,
string[] ranges = cmbrate.SelectedValue.ToString().Split('-');
comm.Parameters.AddWithValue("@Range",ranges[1]);
mani replied to Subhashini Janakiraman
i tried u r code..
string[] ranges = cmbrate.SelectedValue.ToString().Split('-');
comm.Parameters.AddWithValue("@range_from",ranges[0]);
comm.Parameters.AddWithValue("@range_to",ranges[1]);
comm.Parameters.AddWithValue("@percentage", percentage);
but i am getting an error ua
object reference is not set to an instances of obj...
Subhashini Janakiraman replied to mani
Here is my modified code.Try one more time so that it helps,
Here is my code for your query.Hope it helps...
string[] ranges = cmbrate.SelectedValue.ToString().Split('-');
comm.Parameters.AddWithValue("@Rangefrom",Convert.ToInt32(ranges[0]));
comm.Parameters.AddWithValue("@Rangeto,Convert.ToInt32(ranges[1]));
(or) simply like,
string[] ranges = cmbrate.SelectedValue.ToString().Split('-');
comm.Parameters.AddWithValue("@Range",Convert.ToInt32(ranges[1]));

empid ! = null ) { SetValue(empid); } } private void SetValue( string empid) { string constr = ConfigurationManager .ConnectionStrings[ "ConStr" ].ToString(); SqlConnection con = new SqlConnection (constr); con.Open(); SqlCommand cmd = new SqlCommand ( "Usp_SelEmpById" , con); cmd.Parameters.AddWithValue( "@empid" , empid); cmd.CommandType = CommandType .StoredProcedure; SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { txtname.Text EventArgs e) { string empid = ( string )Request.QueryString[ "empid" ]; { try { string constr = ConfigurationManager .ConnectionStrings[ "ConStr" ].ToString(); SqlConnection con = new SqlConnection (constr); con.Open(); SqlCommand cmd = new SqlCommand ( "[Usp_UpdateEmployee]" , con); cmd.Parameters.AddWithValue( "@name" , txtname.Text); cmd.Parameters.AddWithValue( "@salary" , txtsalary.Text); cmd.Parameters.AddWithValue( "@doj" , Convert .ToDateTime(txtDOJ.Text)); cmd.Parameters.AddWithValue( "@dob" , Convert .ToDateTime(txtDOB.Text)); cmd.Parameters
Store Procedure can anyone tell me how to implement store procedure in Asp .net with c# First open Microsoft SQL Server -> Enterprise Manager, then navigate to the database in which you want to create the stored procedure and select New Stored Procedure. See the below Stored Procedure Properties for what to enter
inserting all form values in a table using stored procedure hi everyone. . . . . . i have problem like . . .i have created a web page which is having and type which is a dropdownlist and the rest are textboxes and i have created stored procedures to insert these all values into the table but now from my web page how can i cal that stored procedure to insert all my values into table i tried like this but in between i stucked. . . . sqlconnection con = new sqlconnection(); sqlcommand cmd = new sqlcommand("proc_name", con); cmd.commandtype = commandtype.storedprocedure ; so next am trying code
JDBC in Java). It's been around since the first release of .NET. LINQ to SQL is a data access framework built on ADO.NET and new language features that makes SQL Server data available natively in the object oriented style of programming. Also see the examples http agilior.pt / blogs / pedro.rainho / archive / 2008 / 07 / 02 / 4935.aspx LINQ to SQL and the Entity Framework have a lot in common, but each have features targeting different scenarios in the Orcas timeframe. LINQ to SQL has features targeting “ Rapid Development ” against a Microsoft SQL Server database. Think of LINQ to SQL as allowing you to have a strongly-typed view of your existing database schema. LINQ
how to use stored procedure for insert update delete or select Hi all how i cna use stored procedure for insert update delete or select in my application. thanks Regards Shoaib USE [AdventureWorksLT] CREATE Procedure [dbo].[InsertCustomer] @NameStyle bit, @Title nvarchar(8), @FirstName nvarchar(50), @MiddleName nvarchar(50), @LastName nvarchar SalesPerson , @EmailAddress, @Phone, @PasswordHash, @PasswordSalt, @ModifiedDate, @Inactive ) select SCOPE_IDENTITY() as NewCustomerID UPDATE USE [AdventureWorksLT] CREATE PROCEDURE [dbo].[UpdateCustomer] @CustomerID int, @NameStyle bit, @Title nvarchar(8), @FirstName nvarchar(50), @MiddleName nvarchar(50 PasswordHash] = @PasswordHash, [PasswordSalt] = @PasswordSalt, [ModifiedDate] = @ModifiedDate, [Inactive] = @Inactive WHERE CustomerID = @CUstomerID DELETE USE [AdventureWorksLT] CREATE PROCEDURE [dbo].[DeleteCustomer] @CustomerID int AS DELETE FROM Customer WHERE CustomerID = @CUstomerID See this below examples of different scenarios of writing storedprocedure SelectEmployees CREATE PROCEDURE SelectEmployees AS SELECT [EmployeeID], [LastName], [FirstName], [Title], [HireDate], [Address] FROM [Employees] GO UpdateEmployee CREATE PROCEDURE