Problems Inserting And Updating Data Into Sql Database
Mar 26, 2008
i am creating a database driven website and i am using a sql database. I have a database called company with fields in it to do with a company, I have created a company.cs file which sets the variables, properties and methods and so on. These work fine. I have also stored procedures and they are right as far as i know. i also have coding behind the buttons of my page when i try and update or insert to the database. I am having the problem of when i enter data into the text boxes and click update, nothing gets inserted or updated and whats worst of all no error message appears. The table is used for storing profile data about a user, when a user logs on they enter their profile data, if i manually enter this data and input the username of a user into the username field within the database then the data appears fine in the textboxes of the update info page but the data will not insert or update. i have checked all the little things and i am stressing out cos i am running out of time and cannot find the problem...........please could someone help me!!!!! thanks
Heres my coding to some of my pages to help you....
the code behind the button
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FYPtestsite.Classes;
public partial class Employer_employerprofile : System.Web.UI.Page
I am very new to SQL Server 2005. I have created a package to load data from a flat delimited file to a database table. The initial load has worked. However, in the future, I will have flat files used to update the table. Some of the records will need to be inserted and some will need to update existing rows. I am trying to do this from SSIS. However, I am very lost as to how to do this.
Hello friends.... I am looking for 2 things(using c#.net or vb.net and sql svr 2000) 1.convert data from sql server 2000 database (say customers table from northwinds database) to a text file(separated by commas or just plain space) 2.Insert the data from text file back to database. Can someone pls give me the detailed code to achieve this....really need this on urgent basis.......Thank You.
Hi iam working with the form which has fields like AuditName,Industry Name,Company Name,Plant Name,Group Name,AuditStartedOn,Auditperiod upto,CreatedOn,createdby I have dropdownlists for Industry Name,Company Name,Plant Name,Group Name.Data will be filled into Industry Name,Group Name when pageloads from the database and later depending on industryname company name and depending on company name plant name ddl's wiil be filled. Later to insert this into the Audit table i had given the Stored procedure as : create procedure CreateAudit ( @AuditName nvarchar(50), @IndustryName nvarchar(50), @IndustryID int output, @CompanyName nvarchar(50), @CompanyID int output, @PlantName nvarchar(50), @PlantID int output, @GroupName nvarchar(50), @GroupID int output, @AuditStartedOn datetime, @AuditScheduledto datetime, @CreatedOn datetime, @CreatedBy int ) as begin //Here iam getting the Id of the industryname selected in the ddl from industry table into an output parameter @IndustryID select @IndustryID=Ind_Id_PK from Industry where Industry_Name=@IndustryName //Here iam getting the Id of the companyname selected in the ddl from company table into an output parameter @CompanyID select @CompanyID=Cmp_ID_PK from Company where Company_Name=@CompanyName //Here iam getting the Id of the plantname selected in the ddl from plant table into an output parameter @PlantID select @PlantID=Pl_ID_PK from Plant where Plant_Name=@PlantName //Here iam getting the Id of the Groupname selected in the ddl from Group table into an output parameter @GroupID select @GroupID=G_ID_PK from Groups where Groups_Name=@GroupName Insert into Audits(Audit_Name,Audit_Industry,Audit_Company,Audit_Plant,Audit_Group,Audit_Started_On,Audit_Scheduledto,Audit_Created_On,Audit_Created_By)values(@AuditName,@IndustryID,@CompanyID,@PlantID,@GroupID,@AuditStartedOn,@AuditScheduledto,@CreatedOn,@CreatedBy) end Later called these parameters into class file:
namespace xyz{ public class clsCreateAudit {SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["constr"]); SqlCommand cmd = new SqlCommand();SqlDataAdapter da = new SqlDataAdapter();public clsCreateAudit() { con.Open(); }public void CreateAudit(string Audit_Name, int Audit_Industry, int Audit_Company, int Audit_Plant, int Audit_Group, DateTime Audit_Started_On, DateTime Audit_Scheduledto, DateTime Audit_Created_On, string Audit_Created_By) { cmd.Connection = con;cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "CreateAudit"; SqlParameter AuditName = new SqlParameter();AuditName.ParameterName = "@AuditName";AuditName.DbType = DbType.String; AuditName.Value = Audit_Name;AuditName.Direction = ParameterDirection.Input; cmd.Parameters.Add(AuditName); SqlParameter AuditIndustry = new SqlParameter();AuditIndustry.ParameterName = "@IndustryName";AuditIndustry.Direction = ParameterDirection.Input; AuditIndustry.Value = Audit_Industry;AuditIndustry.DbType = DbType.String; cmd.Parameters.Add(AuditIndustry); SqlParameter IndustryID = new SqlParameter();IndustryID.ParameterName = "@IndustryID"; IndustryID.Direction = ParameterDirection.Output;IndustryID.DbType = DbType.Int32; //IndustryID.Size = 100; cmd.Parameters.Add(IndustryID);SqlParameter AuditCompany = new SqlParameter(); AuditCompany.ParameterName = "@CompanyName";AuditCompany.Direction = ParameterDirection.Input; AuditCompany.Value = Audit_Company;AuditCompany.DbType = DbType.String; cmd.Parameters.Add(AuditCompany);SqlParameter CompanyID = new SqlParameter(); CompanyID.ParameterName = "@CompanyID";CompanyID.Direction = ParameterDirection.Output; CompanyID.DbType = DbType.Int32; //IndustryID.Size = 100; cmd.Parameters.Add(CompanyID); SqlParameter AuditPlant = new SqlParameter(); AuditPlant.ParameterName = "@PlantName";AuditPlant.Direction = ParameterDirection.Input; AuditPlant.Value = Audit_Plant;AuditPlant.DbType = DbType.String; cmd.Parameters.Add(AuditPlant);SqlParameter PlantID = new SqlParameter(); PlantID.ParameterName = "@PlantID";PlantID.Direction = ParameterDirection.Output; PlantID.DbType = DbType.Int32; //IndustryID.Size = 100; cmd.Parameters.Add(PlantID);SqlParameter AuditGroup = new SqlParameter(); AuditGroup.ParameterName = "@GroupName";AuditGroup.Direction = ParameterDirection.Input; AuditGroup.Value = Audit_Group;AuditGroup.DbType = DbType.String; cmd.Parameters.Add(AuditGroup);SqlParameter GroupID = new SqlParameter(); GroupID.ParameterName = "@GroupID";GroupID.Direction = ParameterDirection.Output; GroupID.DbType = DbType.Int32; //IndustryID.Size = 100; cmd.Parameters.Add(GroupID);SqlParameter AuditStartedOn = new SqlParameter(); AuditStartedOn.ParameterName = "@AuditStartedOn";AuditStartedOn.Direction = ParameterDirection.Input; AuditStartedOn.Value = Audit_Started_On;AuditStartedOn.DbType = DbType.String; cmd.Parameters.Add(AuditStartedOn);SqlParameter AuditScheduledto = new SqlParameter(); AuditScheduledto.ParameterName = "@AuditScheduledto";AuditScheduledto.Direction = ParameterDirection.Input; AuditScheduledto.Value = Audit_Scheduledto;AuditScheduledto.DbType = DbType.String; cmd.Parameters.Add(AuditScheduledto);SqlParameter CreatedOn = new SqlParameter(); CreatedOn.ParameterName = "@CreatedOn";CreatedOn.Direction = ParameterDirection.Input; CreatedOn.Value = Audit_Created_On;CreatedOn.DbType = DbType.String; cmd.Parameters.Add(CreatedOn);SqlParameter CreatedBy = new SqlParameter(); CreatedBy.ParameterName = "@CreatedBy";CreatedBy.Direction = ParameterDirection.Input; CreatedBy.Value = Audit_Created_By;CreatedBy.DbType = DbType.Int32; cmd.Parameters.Add(CreatedBy); cmd.ExecuteNonQuery(); con.Close(); } } } Then i called these function into .aspx.cs file:
using xyz;protected void btn_CreateAudit_Click(object sender, EventArgs e) {SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["constr"]); PCRA.clsCreateAudit obj = new PCRA.clsCreateAudit(); SqlCommand cmd = new SqlCommand(); //Iam getting the Session(UID) from my login page.obj.CreateAudit(txt_AuditName.Text, Convert.ToInt32(ddl_Industry.SelectedItem.Value), Convert.ToInt32(ddl_Company.SelectedItem.Value), Convert.ToInt32(ddl_Plant.SelectedItem.Value), Convert.ToInt32(ddl_Group.SelectedItem.Value), Convert.ToDateTime(txt_StartingOn.Text.ToString()), Convert.ToDateTime(txt_AuditPeriod.Text.ToString()), System.DateTime.Now, Session["UID"].ToString());lbl_Mesg.Text = "Your Audit Details are added succesfully"; }
But iam getting an error here near obj.CreateAudit as: Input string was not in a correct format. I even want to know if my storedprocedure reaches the requirement which i specified. please help me with this.Its very urgent.
Following are statement which I am using when inserting data into database
INSERT INTO EMPLOYEE (NAME, TELEPHONE, PINNUM,CELLNUM) SELECT NAME,TELEPHONE,PINNUM FROM EMPLOYEE WHERE EMPLOYEEID=1
Noticed that I dont have CELLNUM In my select statment, but I want to insert that number from textbox which I have on my webform. can some one tell me how do i do this query so i can insert data into database.
i am using visual web developer 2005 and SQL Express 2005 with VB as the code behindi have a button and in the button click event i have written codes to INSERT to a database table - it has one primary keyso when i click the button, if there is already a row with primary key fields value as 10 and if i try to INSERT with the same value in the primary key field there will occur primary key constraintso , if i try to INSERT with the already existing primary key fields value, instead of INSERTing it should be UPDATEd without generating any errorplease help me
Does anybody have a sample SQL script that will select table A and compare it to table B. If a row exists in both table A and table B, it will update the columns in table B with the columns in table A. If the row does not exist in table B, it will insert a row in table B using the row in table A. Is this possible?
my requirment is insert TableName and JourneyDate and FlightNumber alongwith otherdata at RunTime but i get error, I tried it several times. Table Structure is: Create Table HA142 ( JourneyDate DateTime primary key, FlightNo char(5)not null FOREIGN kEY REFERENCES FLIGHTS(FlightNo), FirstClassSeatAvalable int, BusinessClassSeatAvalable int, EconomyClassSeatAvalable int, FsWaitingAvalable int, BsWaitingAvalable int, EcWaitingAvalable int ) string flightno = drpFlightNo.SelectedItem.Text; string JourneyDate = Session["JourneyDate"].ToString(); string newStrign = ",18,42,280,3,7,35)"; SqlConnection myConn = new SqlConnection("workstation id=JASIM;packet size=4096;user id=ASPNET;data source=JASIM;persist security info=False;initial catalog=Test"); SqlCommand populateFlightTable = new SqlCommand("INSERT INTO "+flightno+" VALUES("+JourneyDate+","+flightno+newStrign,myConn); myConn.Open(); populateFlightTable.ExecuteNonQuery(); myConn.Close(); whenever compiler reached to populateFlightTable.ExecuteNonQuery(); I received error. i tried it to rectify several times but no result.plz hemp me...
Hi all, I want to insert some data that from a table into a database, and I got the error message-- "The variable name '@IssueID' has already been declared. Variable names must be unique within a query batch or stored procedure." Is it anything wrong with my code? Thanks a lot.
Dim row As Data.DataRow For Each row In table.Rows DataSource.InsertParameters.Add("IssueID", row(0)) DataSource.InsertParameters.Add("UserName", Session("loginName")) DataSource.InsertParameters.Add("IssueCost", row(1)) DataSource.InsertParameters.Add("IssueDesc", row(2)) DataSource.Insert() Next row
How can i insert test Data in to the Database,I want to insert one million records in to the table,This is to test Database Performance. Can anyone help me in this regard,Do we have any scripts for this purpose??? thanks Mar
Hello, is it possible to insert new data into a datbasealphabetically? For example when a user enters a new row of data, Iwant the row inserted in the correct order. I do not think this ispossible.Thank you for the help!
I have an asp.net project that displays a timesheet based on a fortnightly system.
It has a Y and X axis, i.e. Sun-Mon, Sun-Mon across the top and Categories of hour types accross the Y axis, i.e. Holidays, Overtime, Maintenance.
I was using a datagrid to gather the rows, but I need to have the whole grid in edit mode which is something that requires more coding. So I have swapped to a datalist.
It will take me 240 fields to store all the data in their corresponding fields. So I basically need to know if there is an easier way to store two dimensional array type data into an SQL table using a minimum of fields.
SQLNewbie writes "I have a table 'ImportedListings' that is populated with data external to the database. This table is only used to hold the data until I can move it to the permanent table 'Listings' at which point 'ImportedListings' gets truncated to nothing. Both tables contain almost identical data and structure. There is a listing ID column available for joins.
Basically I need to compare each row in ImportedListing and if it already exists in Listing, UPDATE Listing with the new info. If the row in ImportedListing doesn't exist in Listing, I need to INSERT it.
Physically deleting rows from the listings table is not an option. Do you have any ideas on how I can do this? I initially tried using a temp table to hold the matching listing id's but I could not get figure out the update statement with this scenario.
Thanks for any help! I have been trying to hammer this out all night(I just started programming tsql)"
Hi everyone!Hope that someone can help me solving this problem.I have a form where the user can register by putting his private data. Each time that he submits his data, if he is using Internet Explorer, it will insert blank data into sql server database. But if user is using Firefox, everything is working well, and all data is inserted.What seems to be the problem?Why in IE, data is inserted as blank?!Thanks for your possible help and attention to this issue.Hope that someone can help me.Best regards,Mesk
I am trying to implement a code behind page (in VB) to insert data into a sql express database but something is not right. Any help would be greatly appreciated. The following is the code I have:Protected Sub SaveButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveButton.Click Dim connString As String = "Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|News.mdf;Integrated Security=True;User Instance=True;Asynchronous Processing=true" Dim sqlInsert As String = "INSERT INTO news_Article (Heading, Story, Author, Show_on_homepage) VALUES(@heading, @story, @author, @show)" Dim conn As New System.Data.SqlClient.SqlConnection(connString) Dim cmd As New System.Data.SqlClient.SqlCommand(sqlInsert, conn) Dim heading = HeadingTextBox.Text Dim story = StoryEditor.Value Dim author = AuthorTextBox.Text Dim show = ShowHPCheckBox.Checked conn.Open() cmd.BeginExecuteNonQuery() conn.Close()End Sub
hi I want to read data from XML file and insert that data from XML file into the Database Table From ASP.NET page.plz give me the code to do this using DataAdapter.Update(ds)
what i understand if if the data field is integer or money, not string, then i need to do a convert(datatype, value) in the insert but how come its still not working INSERT INTO [Product] ([Title], [Description], [Processor], [Motherboard], [Chipset], [RAM], [HDD], [OpticalDrive], [Graphics], [Sound], [Speakers], [LCD], [Keyboard], [Mouse], [Chassis], [PSU], [Price]) VALUES (@Title, @Description, @Processor, @Motherboard, @Chipset, @RAM, @HDD, @OpticalDrive, @Graphics, @Sound, @Speakers, @LCD, @Keyboard, @Mouse, @Chassis, @PSU, convert(smallmoney, @Price))
Hi! I have a vb.net program that writes data to an SQL Server database using ADODB. The problem is if I put the code that writes data to the database in between BeginTrans() and CommitTrans(), the database is not updated. Here is the flow of my program:
Dim connection as ADODB.Connection 'setup the connection to the SQL Server database here
connection.BeginTrans()
InsertData() ' --> data is written to the database ' this function works properly
connection.CommitTrans()
If I comment out the BeginTrans() and CommitTrans() functions, the data is properly inserted into the database.
Does an SQL Server database requires special settings to support transactions?
I have question on lock on table in SQL Server while inserting data using multiple processes at a single time into same table.Here are my questions on this,
1) Is it default behavior of SQL server to lock table while doing insert? 2) if yes to Q1, then how we can implicitly mention while inserting data. 3) If I have 4 tables and one table is having foreign keys from rest of the 3 tables, on this scenario do I need to use the table lock explicitly or without that I can insert records into those tables?
i wanted to ask how to insert values from a single web form into two sql tables, i have been looking and the visual web developer i use doesnt seam to allow me to even atempt it i've tried selecting all the values from two different tables and then adding those two tables to an insert function but it doesnt work likewise the update functioni have values in a table currently a reference number and i want to use this reference number to update the address values in this table so update this field.table1 and thisfield.table2 when ref number = @ refnumber the reference number is present in both tables and is linked PK to FK <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Back End DataConnectionString %>" SelectCommand="SELECT StartDetails.StartDetailsID, StartDetails.ContractIDNo, StartDetails.ContractName, StartDetails.NINO, StartDetails.AnticipatedStartDate, StartDetails.StartDateTime, StartDetails.StartDateLetterSent, StartDetails.StartDate, StartDetails.AnticipatedEndDate, StartDetails.ActualEndDate, StartDetails.ReasonForLeaving, StartDetails.Provider, StartDetails.AdviserReferrer, StartDetails.ProvisionCat, StartDetails.Provision, ClientDetails.NINO AS Expr1, ClientDetails.CentreNo, ClientDetails.FirstName, ClientDetails.SecondName, ClientDetails.AddressLine1, ClientDetails.AddressLine2, ClientDetails.PostCode, ClientDetails.ContactTelephoneNumber, ClientDetails.MobileNo, ClientDetails.Email, ClientDetails.DateOfBirth, ClientDetails.Gender, ClientDetails.PWD, ClientDetails.Ethnicity, ClientDetails.ClientGroup, ClientDetails.RepeatStartDate, ClientDetails.CaseworkerName, ClientDetails.ClientStatus, ClientDetails.PlacementDates, ClientDetails.JobsearchDay, ClientDetails.AchievedILP, ClientDetails.JobDate, ClientDetails.JobDate2, ClientDetails.JobDate3, ClientDetails.EligibleForRolledUpWeeks, ClientDetails.NoOfWeeksClaimed, ClientDetails.MarketingWhere, ClientDetails.Notes, ClientDetails.JobCentre, ClientDetails.JobCentreRep FROM StartDetails INNER JOIN ClientDetails ON StartDetails.NINO = ClientDetails.NINO WHERE (StartDetails.StartDetailsID = @StartDetailsID) AND (StartDetails.NINO = @NINO)" InsertCommand="INSERT INTO [StartDetails] ([NINO], [StartDate], [AnticipatedEndDate]) VALUES (@NINO, @StartDate, @AnticipatedEndDate)"
Hi, I'm trying to store large strings to a database, so am using thetext field type (LongText). I have used this before when storing thehtml of a webpage, and was able to store more than 255 characters byusing just a normal update sql statement. Now I'm trying to store thebody of research papers, and must be doing something different, as Ican only store 255 characters.Can someone explain why SQL Server doesn't like what I am doing -should I be using the WriteText / UpdateText function? If so, pleaseexplain by example how I would do that, and why doing that works.Thanks so much,Iain
I have created a single Data Flow Task that reads a set of records from a source table and then makes determinations whether to insert, update or delete from a destination table. The data is basically being copied from one database to another with a small amount of data manipulation and lookups. The problem seems to be that when running the task, even a small amount of records read from the source table seem to take a long time for the task to finish. I feed the records into a Script Component (the brains) that sorts the records to three separate outputs. I use OLE DB Commands to perform the DELETE and UPDATE and an OLE DB Destination for INSERT. I thought that by using three separate database connections would help, but it just appears to be locked while trying to perform these commands against the same table.
Is there a way to control or route these three record sets in such a way as to perform them sequentially?
I know it's a bit of a simple question for some of you, but I'm just learning SSIS (but I like it!).
I developed a console application that will continually check a messagequeue to watch for any incoming data that needs to be inserted into MSSQL database.What would be a low-cost method I could use inside this consoleapplication to make sure the MS SQL database is operational before Iperform the insert?
I am using the following query to calculate date differences:select ..........DATEDIFF(d, recruitment_advertising.advertising_date, career_details.RTS_Email AS Datetime) AS Ad_to_RTS_days FROM .....I have stored all my dates as NVARCHAR because of the issues with localization.If the value is an empty String my output is eg: -38700. which is way off and incorrect. Some of the values in my table are NULL and they produce the correct result.Is there a T-SQL statement to replace empy Strings with the NULL value in my tables.I'd like to use it as a trigger when inserting or updating to convert empty strings to NULLbefore the values are inserted.Thanks guys.
Hello.I've read many topics about this problem but i couldn't figure it out.I use form where user must insert 2 dates using texboxes.-One is required and other is optional.Sql 2000 is inserting either '20061105' or '2006.11.05' on insert update but select query returns 05.11.2006 on my report. Question 1.How do I insert or update dates from my form where date is entered dd.mm.yyyy to sql 2000 table?question 2. What to do if user left optional texbox date empty.I'm using SP and function with arguments (byval texbox1.text as date, byval texbox2.text as date)and parameters @date1, sqldbtype date =texbox1.text
We've installed the Oracle provider for OLE DB on SQL Server 2005, which has the default collation (SQL_Latin1_General_CP1_CI_AS), and we've created a linked server for the Oracle 9.2.0.5 database, which has AL32UTF8 as the database character set. We can successfully insert strings into VARCHAR2 columns on Oracle from SQL Server via EXEC SP_EXECUTESQL('INSERT OPENQUERY(...) VALUES(...)') -- as long as the strings (whether selected from NVARCHAR columns on SQL Server or specified as literals with the N prefix during testing) only contain Windows-1252 characters.
If the SQL statement contains a character above U+00FF, the string on the Oracle side is incorrectly/doubly encoded; there are nearly (but not exactly) 4 bytes per character instead of the 1 or 2 you'd expect from ASCII/Latin-1 characters encoded as UTF-8.
We've tried reconfiguring the linked server: collation compatible = false, use remote collation = true, and collation name = Latin1_General_BIN2. But that had no effect.
Hi Gnite everyone, i once again need help with a T-SQL syntax for Auto Correction for insert and update when client enters the wrong format, i;e, creating a SSN Data type and a User Defined Procedure that auto corrects input format i;e, user inserts into table authors of the pubs DB 525-477845 column au_id that executes auto correction so user doesn't have to put in dashes for SSN format. Please help me with this syntax .
I have two databases im working with, one is our public database GRM_Public, and the other is our production database GRM_Prod.
I'm trying to import data from a field called 'oldscreencodes1' from GRM_Prod.Transfer table into a field called 'Sale1Type' in GRM_Public.Real_land table.
For some reason I can't get this to work, I have in the past imported datatables from our production DB to our public DB by using 'insert into' but I've never inserted data into a single field within a datatable and I think I'm over thinking this process.
Is a 'join' necessary in order to accomplish this?
Inside a single transaction I'm inserting/updating multiple records into multiple tables, in this order: table 1 record 1 table 2 record 1 table 3 record 1 table 1 record 2 table 2 record 1 table 1 record 3 table 2 record 3 table 3 record 3
Now I'm getting an unspecified error on a certain table:
Indicates a data modification, such as an insert, an update, or a deletion. Ensures that multiple updates cannot be made to the same resource at the same time. (I assume that multiple updates within the SAME transaction can be made, only multiple updates from different transaction cannot be made, right?) I cannot find any reference to this error message and don't know what the numbers mean. Maybe it relates to data that can be found in the sys.lock_information table like explained here, http://technet.microsoft.com/en-us/library/ms172932.aspx, but I'm not sure.
Furthermore, the sys.lock_information table is empty. I haven't been able to reproduce the problem myself. I only received an error log and the database to investigate it.
So, does anybody have an idea what this error message means and what I can do to troubleshoot this?
4 Layered Web Application for Inserting data into a database using sql server as the back end and a web form as the front end using C# . Can someone provide with code as I am new to this architecture and framework. Better send email. Thanks In Advance, A New Bie