Posts

Showing posts from October, 2021

Donate

SQLBulkCopy Error - The given value of type String from the data source cannot be converted to type nvarchar of the specified target column. String or binary data would be truncated.

Image
Good day! Normally, in a situation where you want to inject thousands of rows to the database using C# and SQL Server, the optimal solution would be using built-in SQLBulkCopy() function. However, you may encounter the error message "The given value of type String from the data source cannot be converted to type nvarchar of the specified target column. String or binary data would be truncated." The code below works but in some instance may throw that kind of exception. private bool SQLBulkCopy<T>( string SqlConn, List<T> inList, string tableName, ref string errMsg, int optBatchSize = 5000, bool optTableLock = true ) { SqlBulkCopyOptions lockType; SqlTransaction transaction; if (optTableLock) lockType = SqlBulkCopyOptions.TableLock; else lockType = SqlBulkCopyOptions.Default; try { using ( var connection = new SqlConnection(SqlConn)) { connection.Open(); transaction = connection.BeginTransaction(); using ( var bulkCopy

Async Fetch Not Working When Retrieving Data From JSONPlaceholder API In JavaScript And Vue.JS

Image
Hello, I was trying to retrieve data from a Free Fake API website called JSON Placheholder using the code below which using asynchronous behavior. However, this does'nt return data after all. async getDataAsync(){ try { let response = await fetch( 'http://jsonplaceholder.typicode.com/todos' ); console.log(response.data); this .todos = response.data; } catch (error) { console.log(error); } After doing some research, I came up with a solution and replace the code above using JavaScript Promise as a means to retrieve data from the Fake API website in an asynchronous manner. await fetch( 'http://jsonplaceholder.typicode.com/todos' ) .then(response => response.json() ) .then(data => { this .todos = data; }) . catch (error => { return Promise.reject(error); }); } Cheers!

Axios.Get HTTP Client Not Returning Data From API In Vue.js

Image
Good day! I was following a tutorial on how to create a simple tutorial on how to create a Todo List project that retrieves data from a dummy API website in Youtube using the Axios HTTP Client Library. However fetching the API data from jsonplaceholder.typicode.com using Axios get() method does'nt return any results and the browser just rendered the white screen of death. After reading through my code thoroughly, I noticed that I have misplaced the created event inside the methods property which is the culprit of the issue. export default { name: 'home' , components: { Todos, Header, AddTodo }, data(){ return { todos:[], } }, methods:{ deleteTodo(id){ console.log(id); axios. delete (`https: //jsonplaceholder.typicode.com/todos/${id}`) .then(res => { this .todos = this .todos.filter(todo => todo.id !== id) return res }) . catch (error => {

Donate