ado.net

DataTable equivalent in Java [duplicate]

断了今生、忘了曾经 提交于 2019-12-28 02:05:35
问题 This question already has answers here : DataSet class in Java? (9 answers) Closed 6 years ago . Is there a C# DataTable equivalent in Java? 回答1: A similar question that has been asked recently. ResultSet certainly is not a direct equivalent as it only works with an active connection to the database while a DataTable can be used "offline". From personal experience I would say there is no direct equivalent in Java (haven't tried javax.sql.rowset.WebRowSet , though). You either go with plain

Getting binary data using SqlDataReader

给你一囗甜甜゛ 提交于 2019-12-28 02:05:04
问题 I have a table named Blob (Id (int), Data (Image)). I need to use SqlDataReader to get that image data. Note that I dont want to Response.Binarywrite() the data to the browser. I just need that binary data as byte[] to use the same for some internal operations. Only way I can think of is getting id using SqlDataReader and the again use SqlCommand.ExecuteScalar() to get that as byte[] for a given id. Can I use just the SqlDataReader (SqlCommand.ExecuteReader) to get that image data as byte[]?

Getting binary data using SqlDataReader

拜拜、爱过 提交于 2019-12-28 02:04:46
问题 I have a table named Blob (Id (int), Data (Image)). I need to use SqlDataReader to get that image data. Note that I dont want to Response.Binarywrite() the data to the browser. I just need that binary data as byte[] to use the same for some internal operations. Only way I can think of is getting id using SqlDataReader and the again use SqlCommand.ExecuteScalar() to get that as byte[] for a given id. Can I use just the SqlDataReader (SqlCommand.ExecuteReader) to get that image data as byte[]?

How should I multiple insert multiple records?

强颜欢笑 提交于 2019-12-28 01:55:09
问题 I have a class named Entry declared like this: class Entry{ string Id {get;set;} string Name {get;set;} } and then a method that will accept multiple such Entry objects for insertion into the database using ADO.NET: static void InsertEntries(IEnumerable<Entry> entries){ //build a SqlCommand object using(SqlCommand cmd = new SqlCommand()){ ... const string refcmdText = "INSERT INTO Entries (id, name) VALUES (@id{0},@name{0});"; int count = 0; string query = string.Empty; //build a large query

Is it possible to run native sql with entity framework?

核能气质少年 提交于 2019-12-27 17:09:51
问题 I am trying to search an XML field within a table, This is not supported with EF. Without using pure Ado.net is possible to have native SQL support with EF? 回答1: For .NET Framework version 4 and above: use ObjectContext.ExecuteStoreCommand() if your query returns no results, and use ObjectContext.ExecuteStoreQuery if your query returns results. For previous .NET Framework versions, here's a sample illustrating what to do. Replace ExecuteNonQuery() as needed if your query returns results.

How to pass sqlparameter to IN()? [duplicate]

末鹿安然 提交于 2019-12-27 12:17:26
问题 This question already has answers here : Pass Array Parameter in SqlCommand (11 answers) Closed 3 years ago . For some reason the Sqlparameter for my IN() clause is not working. The code compiles fine, and the query works if I substitute the parameter with the actual values StringBuilder sb = new StringBuilder(); foreach (User user in UserList) { sb.Append(user.UserId + ","); } string userIds = sb.ToString(); userIds = userIds.TrimEnd(new char[] { ',' }); SELECT userId, username FROM Users

SQL timeout exception

a 夏天 提交于 2019-12-25 19:15:14
问题 Why do I get this exception in my code? I restarted the server, changed ports, etc, but nothing is working. What's wrong? DataTable dt = new DataTable(); SqlConnection con = new SqlConnection("server=localhost;user=armin;password=root;"); con.Open(); SqlCommand result = new SqlCommand( "SELECT userid FROM KDDData.dbo.userprofile order by userid", con); SqlDataReader reader = result.ExecuteReader(); dt.Load(reader); List<string> userids = new List<string>(dt.Rows.Count); foreach (DataRow item

Entity Framework insert doesn't work

假装没事ソ 提交于 2019-12-25 18:26:43
问题 I have a very simple windows form project with Entity Framework. Simply I draged my tables from "Data Source" tab in my "form" and it generate for me a "DataGridView" and a "BindingSource". Data bound successfully and when I run project I can see "DataGridView" filled with data correctly and I can update any cells value from "DataGridView". Problem is I can not insert any rows in my "DataGridView". Here is some codes that I wrote hope it be useful to solve problem: Teachers_DBEntities context

Entity Framework insert doesn't work

梦想与她 提交于 2019-12-25 18:26:37
问题 I have a very simple windows form project with Entity Framework. Simply I draged my tables from "Data Source" tab in my "form" and it generate for me a "DataGridView" and a "BindingSource". Data bound successfully and when I run project I can see "DataGridView" filled with data correctly and I can update any cells value from "DataGridView". Problem is I can not insert any rows in my "DataGridView". Here is some codes that I wrote hope it be useful to solve problem: Teachers_DBEntities context

can't add a .accde MS access file(located outside the project folder) as AccessDataSource

南楼画角 提交于 2019-12-25 17:48:48
问题 I'm pretty sure that the .accde file does exist. I noticed that VS asks for .mdb file, but a .accde is also a MS Access generated database file. Here is the screenshot(hope it helps): 回答1: From the MSDN AccessDataSource page. The AccessDataSource class does not support connecting to Access databases that are protected by a user name or password, because you cannot set the ConnectionString property. If your Access database is protected by a user name or password, use the SqlDataSource control