ado.net

How do I store multiple results from a stored procedure into a dataset?

牧云@^-^@ 提交于 2019-12-29 07:51:12
问题 How do I combine to result sets from a StoredProcedure into one dataset in ASP.NET? Below is my code in asp.net SqlDataAdapter adap = new System.Data.SqlClient.SqlDataAdapter("sp_Home_MainBanner_TopStory",con); adap.SelectCommand.CommandType = CommandType.StoredProcedure; adap.SelectCommand.Parameters.AddWithValue("@rows", 9); DataSet DS = new DataSet(); adap.Fill(DS, "Table1"); adap.Fill(DS, "Table2"); GridView1.DataSource = DS.Tables["Table2"]; GridView1.DataBind(); Even if there were two

Use SqlDataReader in F#

依然范特西╮ 提交于 2019-12-29 07:44:32
问题 In C# I use sql scripts to add data into a List where T would be a class with fields/properties mapped to the sql script. How could I do this in F#? This piece uses a stored procedure in the standard way. using (conn) { conn.Open(); using (SqlCommand cmd = new SqlCommand("dbo.query_here", conn)) { cmd.CommandText = "dbo.query_here"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandTimeout = 600; cmd.Parameters.Add(new SqlParameter("@x1", Convert.ToString(x))); cmd

VS2010 opens my class-file (.cs) in the designer mode

只愿长相守 提交于 2019-12-29 05:44:05
问题 I've created a class that extends DbConnection in a brand new project. public class FakeDbConnection : DbConnection { ... } In the Solution Explorer the class looks like this: And when double-clicking it wants to open it in design mode which won't work. Opening up the .csproj-file reveals the problem <ItemGroup> <Compile Include="FakeADO\FakeDbConnection.cs"> <SubType>Component</SubType> </Compile> </ItemGroup> Even if I remove the SubType tag VS2010 immediately re-adds it. Very annoying. How

in f# match statement how do I match to the type byte[]?

点点圈 提交于 2019-12-28 22:44:54
问题 I'm trying to lookup DbType enumeration values from .net types. I'm using a match statement. However I cannot figure out how to match on the type byte[]. let dbType x = match x with | :? Int64 -> DbType.Int64 | :? Byte[] -> DbType.Binary // this gives an error | _ -> DbType.Object If there is a better way to map these types, I would be open to suggestions. 回答1: byte[] , byte array , and array<byte> are all synonymous, but in this context only the last will work without parentheses: let dbType

“Invalid attempt to call Read when reader is closed” error (for lengthy operations only)

不羁岁月 提交于 2019-12-28 19:16:43
问题 We have a operation in which more than 100.000 records are read from a csv file and inserted in a database. When I am using a file with 10 records, the operation is completed successfully in less than one minute. When I use 100.000 records, I am getting the following error “Invalid attempt to call Read when reader is closed.” after 10 minutes. Is there any Timeout that I can configure to avoid this error? Note: The CommandTimeout is already set as zero. DbCommand cmd = db.GetStoredProcCommand

How do I get values from a SQL database into textboxes using C#?

我只是一个虾纸丫 提交于 2019-12-28 16:25:08
问题 I'm creating a booking management system and I am having problems trying to get data from a SQL database and insert into a group of textboxes of my application. I want to show the customer details, when a button is clicked, in a DataGridView, but when I click the button, the application throws an exception with the following error message; Invalid attempt to read when no data is present. I have attached a screenshot of the screen where I want to view customer details, and the code for the

How do I get values from a SQL database into textboxes using C#?

痴心易碎 提交于 2019-12-28 16:25:06
问题 I'm creating a booking management system and I am having problems trying to get data from a SQL database and insert into a group of textboxes of my application. I want to show the customer details, when a button is clicked, in a DataGridView, but when I click the button, the application throws an exception with the following error message; Invalid attempt to read when no data is present. I have attached a screenshot of the screen where I want to view customer details, and the code for the

Check if SQL Connection is Open or Closed

半城伤御伤魂 提交于 2019-12-28 09:32:57
问题 How do you check if it is open or closed I was using if (SQLOperator.SQLCONNECTION.State.Equals("Open")) however, even the State is 'Open' it fails on this check. 回答1: You should be using SqlConnection.State e.g, using System.Data; if (myConnection != null && myConnection.State == ConnectionState.Closed) { // do something // ... } 回答2: Here is what I'm using: if (mySQLConnection.State != ConnectionState.Open) { mySQLConnection.Close(); mySQLConnection.Open(); } The reason I'm not simply using

How do I connect to a SQL database from C#?

亡梦爱人 提交于 2019-12-28 05:21:49
问题 I am trying to write a local program management and install system for my home network, and I think I've got the technologies nailed down: C#/.NET/WPF for the client Lua for installation scripting support (through LuaInterface) SQL Server Express for maintaining a database of programs However I'm unsure what specifically I'll use to connect C# to the database. Is there something built into the .NET framework for this? Bonus points if you have a suggestion on what I should use for interacting

Refactoring ADO.NET - SqlTransaction vs. TransactionScope

六月ゝ 毕业季﹏ 提交于 2019-12-28 05:15:09
问题 I have "inherited" a little C# method that creates an ADO.NET SqlCommand object and loops over a list of items to be saved to the database (SQL Server 2005). Right now, the traditional SqlConnection/SqlCommand approach is used, and to make sure everything works, the two steps (delete old entries, then insert new ones) are wrapped into an ADO.NET SqlTransaction. using (SqlConnection _con = new SqlConnection(_connectionString)) { using (SqlTransaction _tran = _con.BeginTransaction()) { try {