ado.net

Utilize ADO.NET within Classic ASP script

↘锁芯ラ 提交于 2020-01-02 09:57:10
问题 I'm writing some simple queries which return a single value and I'd like to get the ADO.NET ExecuteScalar method's behavior from Classic ASP's ADO libary. However, I'd prefer to not re-invent the wheel. Is it possible to instantiate ADO.NET's Command object within classic ASP? If so, how would I go about doing that? If I do need to re-implement this feature, what is the best way to do that? Here's what I'm trying to do (In VBScript): set cmd = Server.CreateObject("ADODB.Command") cmd

EF in WinForms: how to filter data in BindingSource/DGW (.Local.ToBindingList())

时间秒杀一切 提交于 2020-01-02 08:56:09
问题 I generated an EF model (Database first) and DataSource following this tutorial http://msdn.microsoft.com/en-us/data/jj682076.aspx On my form I created BindingSource (bsUsers) and bound DataGridView to it. Here is how I load data on form startup: _myDbContext = new MyDbContext(); _myDbContext.Users.Load(); bsUsers.DataSource = _myDbContext.Users.Local.ToBindingList(); It works, I can add and modify records using DataGridView and other bound controls. But the thing I didn't figure out is how

Why does calling AsEnumerable() on a DataTable prevent a GridView from binding to it?

China☆狼群 提交于 2020-01-02 08:54:48
问题 In my .aspx page, I have an <asp:GridView runat="server" ID="CustomerGridView"> control which I bind like this: public partial class InsertCustomer : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ViewCustomer(); } } private void ViewCustomer() { var manager = new DomainManager(); var result = manager.FindAll(new Customer()); this.CustomerGridView.DataSource = result; this.CustomerGridView.DataBind(); } } Here is the DomainManager class: public

c# async when returning LINQ

会有一股神秘感。 提交于 2020-01-02 07:19:33
问题 I've just realised that this code: public async Task<List<Review>> GetTitleReviews(int titleID) { using (var context = new exampleEntities()) { return await context.Reviews.Where(x => x.Title_Id == titleID).ToList(); } } ...will not work as async methods cannot await LINQ expressions. I've did some searches but only managed to find some overcomplicated solutions. How should functions which return LINQ expressions be converted to async versions? 回答1: Add the System.Data.Entity namespace and

SqlException timeout expired without being reached

有些话、适合烂在心里 提交于 2020-01-02 07:14:10
问题 From time to time our server throw this well-known exception: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. This happens under pressure when the server is working on big requests. I did some research and found out that I could change connection string connection timeout setting and/or SqlCommand.Timeout data reader properties. By default, sql command timeout is set to 30 seconds and connection timeout to 15 , and we never

How to specify format of XML output when writing from a DataTable?

為{幸葍}努か 提交于 2020-01-02 07:11:22
问题 In C#, I'm creating an XML file from a DataTable using dataTable.WriteXml(filePath), and get the following: <?xml version="1.0" encoding="utf-8" ?> <ExperienceProfiles> <ExperienceProfile> <Col1>blah</Col1> <Col2>4ed397bf-a4d5-4ace-9d44-8c1a5cdb0f34</Col2> </ExperienceProfile> </ExperienceProfiles> How can I get it to write the XML in the following format?: <?xml version="1.0" encoding="utf-8" ?> <ExperienceProfiles> <ExperienceProfile Col1="blah" Col2="blah" ></ExperienceProfile> <

Multiple Result Sets with Oracle

[亡魂溺海] 提交于 2020-01-02 07:09:09
问题 Simple Question: My code looks like this: var con = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.20.10.8)(PORT=1521))(CONNECT_DATA=(SID=orcl12c)));"); con.Open(); var adp = new OracleDataAdapter("select * from adr;select * from person;", con); var ds = new DataSet(); adp.Fill(ds); Now I would expect to get two tables in the DataSet, but I rather get an exception telling me that the SQL Syntax is not correct... It seems the ; is not recognized that way..? Any

SSIS - Passing Parameters to an ADO .NET Source query

给你一囗甜甜゛ 提交于 2020-01-02 05:37:07
问题 I know this has been asked earlier. Most of the answers were not relevant. Google, shows that the solution is to configure the expression in the "data flow task" and set the query. However in the ADO .NET source, when I try to preview the output I keep getting "Must declare the variable '@'" It does not show the full variable in this error - "@[User::GLOBAL_PARAMETER]" I think that's because "[USER::" isn't the correct syntax inside a SQL; but then how does one set it ?! 回答1: From your

How secure the user name and password in the connection string?

此生再无相见时 提交于 2020-01-02 03:26:25
问题 when developing windows applications: How I secure the user name and password in the connection string? Organizations like banks, would they give out the user name and password of their DB to application developers? if not typically how those applications developers write the DB Connections? What is the industry standard to secure user and password in the connection string? thanks 回答1: How I secure the user name and password in the connection string? Either use Windows authentication to

How to get columns Primary key constraints using SqlConnection.GetSchema()

陌路散爱 提交于 2020-01-02 03:20:10
问题 I have some code of ADO.NET to dynamically detect the database schema, what I need is how to get unique columns constraints and Primary key constraints using the GetSchema method on SqlConnection . This is the code that I have: conn.Open(); SqlCommand mSqlCommand = new SqlCommand("sp_pkeys", conn); mSqlCommand.CommandType = CommandType.StoredProcedure; mSqlCommand.Parameters.Add( "@table_name", SqlDbType.NVarChar).Value = tableName; SqlDataReader mReader = mSqlCommand.ExecuteReader(