dataadapter

C# SQL Data Adapter System.Data.StrongTypingException

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-02 09:15:44
问题 I get my data from SQL to Dataset with Fill. It's just one table with two columns (CategoryId (int) and CategoryName (varchar)). When I look at my dataset after fill method, CategoryId Columns seems to be correct. But in the CategoryName I have a System.Data.StrongTypingExceptio n. What could that mean? Any Ideas? 回答1: When you get the value of a row/column in a typed dataset, by default it raises this exception when the value is DBNull. So string x = Row.CategoryName;//Raises this exception

C# SQL Data Adapter System.Data.StrongTypingException

安稳与你 提交于 2021-02-02 09:13:48
问题 I get my data from SQL to Dataset with Fill. It's just one table with two columns (CategoryId (int) and CategoryName (varchar)). When I look at my dataset after fill method, CategoryId Columns seems to be correct. But in the CategoryName I have a System.Data.StrongTypingExceptio n. What could that mean? Any Ideas? 回答1: When you get the value of a row/column in a typed dataset, by default it raises this exception when the value is DBNull. So string x = Row.CategoryName;//Raises this exception

How could I pass parameter to sqldataadapter?

只谈情不闲聊 提交于 2021-01-28 14:17:24
问题 I have tried to pass parameter a value, but what it returns is nothing. If I use a simple sql command without parameter I can retrieve all the data from my database. Here is my code: Public Shared Function RetrieveData() As DataTable Connection.Open() Try sql = "SELECT DEP_ID AS CODE, DEP_NAME AS DEPARTMENT FROM DEPART_TBL WHERE " & FieldName & " LIKE N'%@criteria%'" da = New SqlDataAdapter da.SelectCommand = New SqlCommand(sql, Connection.SQLConnection) da.SelectCommand.Parameters.Add("

Inserting values into a mysql database does not work as expected

吃可爱长大的小学妹 提交于 2020-07-10 07:06:24
问题 I try to fill a mySQL/ MariaDB table from within C#. Reading the table and populating a dataset works. the table structure and its keys etc. are given and cannot be changed: CREATE TABLE `fhem`.`history` (TIMESTAMP TIMESTAMP, DEVICE varchar(32), TYPE varchar(32), EVENT varchar(512), READING varchar(32), VALUE varchar(32), UNIT varchar(32)); CREATE TABLE `fhem`.`current` (TIMESTAMP TIMESTAMP, DEVICE varchar(32), TYPE varchar(32), EVENT varchar(512), READING varchar(32), VALUE varchar(32), UNIT

DataAdapter: Update unable to find TableMapping['Table'] or DataTable 'Table'

本小妞迷上赌 提交于 2020-06-27 07:57:13
问题 This code snippet is throwing an error: Update unable to find TableMapping['Table'] or DataTable 'Table'.) on adapter.Update(ds); line Why it is throwing this type of error? SqlConnection con = new SqlConnection(); con.ConnectionString = connectionString(); DataSet ds = new DataSet(); string strQuery = "SELECT * FROM Cars"; SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = new SqlCommand(strQuery, con); SqlCommandBuilder builder = new SqlCommandBuilder(adapter); adapter

Update using MySqlDataAdapter doesn't work

╄→гoц情女王★ 提交于 2020-01-13 10:07:52
问题 I am trying to use MySqlDatAdapter to update a MySql table. But, the table never updates!!! I did this before but with SQL server. Is there anything else that is specific to MySql that I am missing in my code? DataTable myTable = new DataTable("testtable"); MySqlConnection mySqlCon = new MySqlConnection(ConfigurationManager.ConnectionStrings["DBConStr"].ConnectionString); MySqlCommand mySqlCmd = new MySqlCommand("SELECT * FROM testtable WHERE Name = 'Tom'"); mySqlCmd.Connection = mySqlCon;

How to track which row update failed in batch update

好久不见. 提交于 2020-01-05 05:45:10
问题 I'm using a try catch blocks to do a batch update using ADO.NET2.0, the UpdateBatchSize is set 500, I can often catch exceptions, but I don't know which row update failed, is there a way to get the actual failed row? 回答1: You can use event RowUpdated to get the reference of row: yourAdapter.RowUpdated += OnRowUpdated; Then: protected static void OnRowUpdated(object sender, SqlRowUpdatedEventArgs args) { if (args.Status == UpdateStatus.ErrorsOccurred) { // Reference to row which throws error

calling a stored procedure from C# using SqlDataAdapter

大憨熊 提交于 2020-01-05 04:12:06
问题 I have a stored procedure which has been well tested and works perfectly from SQL Server Management Studio. All the procedure does is check for the existence of a record in a table, return it if it exists, or create it and then return it if it doesn't. The procedure looks like this: CREATE proc [dbo].[spInsertSerialBatch] @MOS_JOB varchar(12), --PASSED COMMAND LINE @MOS_LOT varchar(4) = NULL, --PASSED COMMAND LINE @MES_USER varchar(12) = 'NOT PASSED',--PASSED COMMAND LINE @COMPUTERNAME

Getting concurrency error on updating record with data adapter

血红的双手。 提交于 2019-12-30 14:44:53
问题 This is my table: Student : StudentId int PK autoincrement,Name varchar(20) When i am trying to update last added records then i am geting error: Error : Concurrency violation: the UpdateCommand affected 0 of the expected 1 records. This is my code: using (var connection = new SqlConnection("MyConnectionstring")) { connection.Open(); SqlDataAdapter adapter = new SqlDataAdapter(); SqlCommandBuilder builder = new SqlCommandBuilder(adapter); adapter.SelectCommand = new SqlCommand("select * from

How to insert child category by specific parent category into table using ado.net?

谁说胖子不能爱 提交于 2019-12-25 07:34:23
问题 I am trying to insert categories and subcategories from Excel into a database table. I have 1 Excel file which contains some data and from this Excel file I am creating dataset which contains lots of datatables . In this dataset I have 2 datatables in the form of this: Datatable 0 with records: Category ParentCategory Description Electronics jhdkhsd Sports kjshfhs Datatable 1 with records: SubCategory Subcategory ParentCategory Description Mobile Electronics weprwp Tv Electronics sdflskd