I have created LINQ to SQL Class and trying to insert one record in application but unable to save record in database table in window application
Table Name : Test
I have two column in table
1) TID Type INT , Primary Key , Identity column
2) Title Type Varchar(50)
I have written below code to save new record in to table, Code running successfully without any error but record not store into application
My code is
DataClasses1DataContext db = new DataClasses1DataContext();
Test t = new Test();
t.Title = "Abhishek";
db.Tests.InsertOnSubmit(t);
db.SubmitChanges();
please help me to resolve this problem
Thanks,
Abhishek
Your code looks fine. But, just before calling SubmitChanges, take a look at db.GetChangeSet() and see if there are any pending inserts. There should be one. If there is one, take a look at the db.Log output and see what is getting sent to SQL Server.
Related
Backend code = java, hibernate, maven, hosted in AEM.
DB = SQL db
Existing table had column of type INT.
Backup of the original table containing that column was made by Select * into backupTable from originalTable
Backup of the audit table (for the original table) containing that column was made by Select * into backupTable_AUDIT from originalTable_AUDIT
Column type INT was changed to VARCHAR(255) by dropping-recreating that column in originalTable.
Column type INT was changed to VARCHAR(255) by dropping-recreating that column in originalTable_AUDIT.
All places in the code that used that column has been changed to accomodate VARCHAR.
BE Code was rebuilt.
Code was deployed.
When trying to run app getting error: "wrong column type encountered in column [mycolumn] in table [originalTable]; found [nvarchar (Types#NVARCHAR)], but expecting [int (Types#INTEGER)])"
After deleting backupTable_AUD => no error any more, all works fine.
As much as I know each table in the db schema has an id.
It seems BE-code/Hibernate was looking at backup table id?
Can somebody please explain more why deleting backup tables did help to eliminate the error,
and which step was missed during deployment/backup to avoid this error?
Many thanks
I have similar issue to one previously posted but none of the answers helped.
I cannot open any form in my DB to a new record.
This all worked before moving tables from Access DB to SQL Server and linking back to them.
All tables have an ID column of datatype integer set as primary key on the server.
All tables have a RowVersion column of datatype datestamp.
All forms are based on a single table as record source.
All columns of datatype = bit have default value set to 0 on the SQL Server.
In Access form, properties are set to allow additions = yes, allow edits = yes, I also set data entry = yes as well which wasn't necessary before SQL server hosted the tables but it didn't help anyway.
I tried on button click event that opens the form:
Private Sub OpenFormNameBtn_Click()
DoCmd.OpenForm "FormName", , , "[CustID]=" & Me![CustID] & " AND [EnvID]= '" & Me![EnvID] & "'"
Forms!DeploymentsF.Form.AllowAdditions = False
Forms!DeploymentsF.Form.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
End Sub
NOTE: the criteria of custid and envId worked when the tables were in access and I need them to stay this way.
The above caused the auto number ID to appear on the form for an instant but then it disappeared just as quickly! In the code behind the submit button at the bottom of the form (to write the record to the table), it errors out and I see where the Form's ID field = Null in debug so it couldn't write the id in the update statement to the table. I CAN, however, insert a record into the table with a query insert statement on the SQL server no problem AND I can edit records in forms and sub forms and it writes to the tables on the SQL Server.
I also tried a simple form with no criteria and no pre-filling and got the error, "Can't go to the specified record"
I tried button click event: DoCmd.OpenForm "FormName", , , , acFormAdd.
Anyone seen this before and have a solution? I'm out of ideas.
I try to add a column to a table with GUI Tableplus, but no response for long time.
So I turn to the db server, but got these error:
Maybe some inconsistent data generated during the operation through the Tableplus.
I am new to postgresql , and don't know what to do next.
-----updated------
I did some operation as #Dri372 told, and got some progress.
The failed reason for table sys_role and s2 is that the tables are not empty, they have some records.
If I run sql like this create table s3 AS SELECT * FROM sys_role; alter table s3 add column project_code varchar(50);, I successed.
Now how could I still work on the table sys_role?
I changed one of the column's name in my db and when I run my app I get this error :
5 10449-10449/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.liavbapps.mascoret, PID: 10449
android.database.sqlite.SQLiteException: no such column: TarrifHolyDay (code 1): , while compiling: UPDATE MySettings SET TarrifHolyDay=?
I know that happens beacuse it try to update a column that doesnt exist in my current db.
If I will open a new db it will contain the new column name , but I lose my data.
My question is how can I update my current db's column name, in oreder to keep my data ?
Thanks!
You need to alter the table, check ALTER TALBE SQL command :
http://www.techonthenet.com/sql/tables/alter_table.php
Take a look of MODIFY COLUMN IN TABLE section.
I can use code like this to extract the columns from a SQL Server 2012 table:
var sqlConnection = new SqlConnection(conns);
var dt = sqlConnection.GetSchema
(SqlClientMetaDataCollectionNames.Columns, new string[] { null , null , "mytable" , null });
However, I am unable to determine the right kind of schema query to get the columns from my user-defined Table type. How is that done?
All ideas appreciated (Using .NET 4.5.1).
Not sure if this is still a relevant question, but I just received an answer to something nearly identical. Check out the answer for this question:
Retrieve UDT table structure in VB.NET
The answer shows how to get a "sanitized" type name from sys.types, then it creates simple sql query in the form:
declare #t MyUDTType; select * from #t;
Then returns the empty DataTable to the calling application.