sqldataadapter

What does MissingSchemaAction.AddWithKey really do?

风格不统一 提交于 2019-12-11 12:36:57
问题 The default value of SqlDataAdapter.MissingSchemaAction is MissingSchemaAction.Add , but when I specify the AddWithKey I can't understand what it really do ? System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(); da.MissingSchemaAction = MissingSchemaAction.AddWithKey; DataSet ds = new DataSet(); da.Fill(ds, "mytable"); When the use of AddWithKey can be useful ? 回答1: Documentation here says, it "adds the necessary columns and primary key information to complete

Can the SqlDataAdapter refresh itself when the table is changed from an outside source?

泪湿孤枕 提交于 2019-12-11 06:05:50
问题 My SQL Server table is updated from outside of my program (from a SQL trigger, actually), so the DataSet doesn't realize that there are changes and my DataGrid doesn't update unless I explicitly call SqlDataAdapter.Fill() again (e.g. with a "Refresh" button or a timed event). Is there a way that ADO.NET can subscribe to change events or such so that it refreshes itself? 回答1: Yes, using Query Notifications. You get a callback when the dataset has changed and you run your query again. 来源: https

SqlDataAdapter.Fill() - Conversion overflow

自作多情 提交于 2019-12-11 05:25:54
问题 All, I am encountering "Conversion overflow" exceptions on one of the SqlDataAdapter.Fill() usages for a decimal field. The error occurs for value beginning 10 billion, but not till 1 billion. Here is the code: DataSet ds = new DataSet(); SqlDataAdapter sd = new SqlDataAdapter(); adapter.SelectCommand = <my SQL Command instance> adapter.Fill(ds); I have read using SqlDataReader as an alternate but we need to set the datatype and precision explicitly. There are at least 70 columns that I am

SQLDataAdapter.Fill() throwing Arithmetic overflow error converting expression to data type datetime

空扰寡人 提交于 2019-12-10 17:56:25
问题 I have a custom method that handles calls to SQL which takes in a script and a list of SqlParamaters , executes the SQL and then fills a DataSet with any results via SqlDataAdapter . This has been in use for over 3 years on various projects without issue. Here is a code snippet of how the custom method is called (the actual SQL script is stored in a file): using (SQLClass _sql = new SQLClass(_Config.DatabaseInfo)) { FileInfo _file = new FileInfo("\\scripts\\GetEmployeeTable.sql"); List

Confused between SqlCommand & SqlDataAdapter

前提是你 提交于 2019-12-09 05:29:26
问题 everyone I am a student and new to .NET and specially MVC3 development but for one of my project I’ve to work over it and so going through the learning phase Issue and confusion I am facing is regarding DB-Connectivity, whast I leanree d regarding retrieving records from a database is something like this: //Method One: var conn = new SqlConnection(conString.ConnectionString); const string cmdString = "Select * FROM table"; var cmd = new SqlCommand(cmdString, conn); var mySqlDataAdapter = new

Should you reuse SqlConnection, SqlDataAdapter, and SqlCommand objects?

空扰寡人 提交于 2019-12-08 19:46:12
问题 I'm working with a DAL object that is written in a layout similar to the following code. I simplified a lot of the code code just to show the setup. public class UserDatabase : IDisposable { private SqlDataAdapter UserDbAdapter; private SqlCommand UserSelectCommand; private SqlCommand UserInsertCommand; private SqlCommand UserUpdateCommand; private SqlCommand UserDeleteCommand; private System.Data.SqlClient.SqlConnection SQLConnection; public UserDatabase() { this.SQLConnection = new System

Is there a more elegant form for assigning NULL to InsertCommand's NVarChar?

纵饮孤独 提交于 2019-12-07 15:55:15
问题 This code works for me very well: if (someStr == null) da.InsertCommand.Parameters.Add("@SOMESTR", SqlDbType.NVarChar).Value = DBNull.Value; else da.InsertCommand.Parameters.Add("@SOMESTR", SqlDbType.NVarChar).Value = someStr; But my intuition tells me that there may be a one-liner version of it. Something like: da.InsertCommand.Parameters.Add("@SOMESTR", SqlDbType.NVarChar).Value = someStr==null ? DBNull.Value : someStr ; But the one-liner I just posted above fails of course because DBNull

How SqlDataAdapter works internally?

一个人想着一个人 提交于 2019-12-07 09:36:48
问题 I wonder how SqlDataAdapter works internally, especially when using UpdateCommand for updating a huge DataTable (since it's usually a lot faster that just sending sql statements from a loop). Here is some idea I have in mind : It creates a prepared sql statement (using SqlCommand.Prepare() ) with CommandText filled and sql parameters initialized with correct sql types. Then, it loops on datarows that need to be updated, and for each record, it updates parameters values, and call SqlCommand

populating a list view with sql database items

荒凉一梦 提交于 2019-12-06 09:39:02
问题 My application is based on displaying a dialog box when the user enters the "add category" button. It then should save data into an SQL Database and populate a list view with each item the user adds. I chose SQL database because I want the data to be saved when the user ends the app. How do I actually populate the list view with those items ? Here is what I have so far: public class CategoryDatabase { public static final String KEY_ROWID = "_id"; public static final String KEY_CATEGORY =

How SqlDataAdapter works internally?

我怕爱的太早我们不能终老 提交于 2019-12-05 16:25:43
I wonder how SqlDataAdapter works internally, especially when using UpdateCommand for updating a huge DataTable (since it's usually a lot faster that just sending sql statements from a loop). Here is some idea I have in mind : It creates a prepared sql statement (using SqlCommand.Prepare() ) with CommandText filled and sql parameters initialized with correct sql types. Then, it loops on datarows that need to be updated, and for each record, it updates parameters values, and call SqlCommand.ExecuteNonQuery() . It creates a bunch of SqlCommand objects with everything filled inside ( CommandText