Tag: ado.net

Inserting values into sqlserver

I have inserted values into sql several times but now i am facing problem with the following code protected void Button1_Click(object sender, EventArgs e) { string connstring = ConfigurationManager.ConnectionStrings[“ConStr”].ConnectionString; con = new SqlConnection(connstring); string name = txtName.Text; string user = txtUser.Text; string password = txtPwd.Text; string email = txtEmail.Text; long phone=Convert.ToInt64(txtPhone.Text); string address = txtAddr.Text; […]

Can I delete records from a sql server table in the middle of a while reader.read loop

I am trying to using a SQL data reader to move records from one table into an archive table. I want to do the transfer record-by-record (instead of inserting and deleting en masse) so that if an error occurs, the minimum amount of data is lost (and has to be restored from backup). My question […]

SqlDataAdapter does not fill DataSet

I’m using VS2012 and SQL Server Express 2008. I’ve boiled down my connection/query to try and find out why my DataSet is not being filled. The connection is completed successfully, and no exceptions are thrown, but the adapter does not fill the DataSet. The database that this is pulling from is on the same PC […]

Create an object inside another class C#?

I’m taking my first steps into oop, which entails gutting my application and reworking it all to be 3-tiered and object oriented. Sigh. I’ve got a submission object, which should contain a customer object (as well as a broker and coverage object); I want to store some datareader results from the db in the fields […]

Unable to add SqlParameter to SqlCommand

This is a strange one to me. The signature of the Add parameter method requires a SqlType but when I use that //Create and open a connection to SQL Server SqlConnection connection = new SqlConnection(DatabaseHelper.ConnectionString); connection.Open(); //Create a Command object SqlCommand command = new SqlCommand( “stpInsertFile”, connection); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(“@LastMod”, System.Data.SqlTypes.SqlDateTime); it shows this […]

Programmatically mapping .NET types onto SQL Server types?

Is there any way to programmatically map a .NET type (such as typeof(int)) into its corresponding SqlDbType (such as SqlDbType.Int)?

Select a data from MS SQL Server 2005

I have a table named t_Student in Microsoft SQL Server 2005 database. In that table there are three columns named student_regiNo, student_Name, student_Email. I’m using following code segment to retrieve “student_Name”. But instead of showing “student_Name” it shows “System.Data.SqlClient.SqlDataReader”. Whats the problem? private void GetDatabaseConnection() { string connectionString = @”server=RZS-F839AD139AA\SQLEXPRESS; Integrated Security = SSPI; database […]

Procedure or function sp_Record has too many arguments specified

This is the code I’m using to insert records into SQL SERVER DB while (dr.Read()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = “sp_InsertEmailRecord”; cmd.Connection = con; cmd.Parameters.AddWithValue(“@mId”, memberId); cmd.Parameters.AddWithValue(“@companyName”, dr.GetValue(0)); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } First Record insert successfully, but when it runs for second it return error Procedure or function sp_Record has too many arguments specified […]

How to create a stored procedure in ADO.NET

I have the following code and i would like it to be a stored procedure. How do you create and call a stored procedure so that the following code is just like a method call. Where are stored procedure stored are they created in Visual studio or in MS SQL Server? using (var conn = […]

System.Data.SqlClient.SqlException: Login failed for user 'sa'

I have launched my site in IIS 7.5.There was an issue in the site and i tried to solve it.after doing the changes i build the solution and tried to check out in the site.At that time i got an exception details as System.Data.SqlClient.SqlException: Login failed for user ‘sa’” this is the source error Line […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.