hi everyone i was wondring if anyone could help me please! i used this code the other day and it was working fine, but then i put this required field validator in and now the sqldatasource is only inserting null values into my database! can someone help me out PLEASE!!!
<SCRIPT runat="server">
Private Sub InsertVote(ByVal Source As Object, ByVal e As EventArgs)
SqlDataSource1.Insert()
End Sub
</SCRIPT>
<form id="form1" runat="server">
Please can you enter your Account ID into the box below, then select the party you wish to vote for by clicking the down arrow and navigatinging to the party of your choice then click the Submit button.
<br />
<br />
Account ID: <asp:TextBox id="TextBox1" runat="server"/>
<br />
<asp:RequiredFieldValidator ID="Validator1"
ControlToValidate="TextBox1" ErrorMessage="Please enter your account number"
runat="server" />
<br /> <br />
Party Selection:
<asp:dropdownlist id="Dropdownlist1" runat="server" datasourceid="SqlDataSource1" datatextfield="Party" AppendDataBoundItems="true">
<asp:ListItem Value="" Text="Please Select"/>
</asp:dropdownlist>
<br />
<asp:RequiredFieldValidator ID="Validator2" ControlToValidate="Dropdownlist1"
ErrorMessage="Please can you select the party you wish to vote for" runat="server"/>
<br />
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
selectcommand="SELECT Party.Party FROM Party"
insertcommand="INSERT INTO Vote(AccountId,Vote) VALUES (Account,Vote)"
ConnectionString="<%$ ConnectionStrings:VotingConnectionString %>"
ProviderName="<%$ ConnectionStrings:VotingConnectionString.ProviderN ame %>">
<InsertParameters>
<asp:FormParameter Name="Account" Type="String" FormField="AccountNumber" />
<asp:FormParameter Name="Party" Type="String" FormField="PartyList" />
We have been asked to look into using stored procedures with SQL Server 7.0 as a way to speed up a clients site. 99% of all the articles I have read along with all the books all say Stored Procedure should be used whenever possible as opposed to putting the SQL in your ASP script. However one of my colleagues has been speaking to Microsoft and they said that that they were surprised that our client wanted to use Stored Procedures as this was the old method of database access and that now he should really consider using COM objects for data access as itis much faster. Has anyone got any views on this or know of any good aticles regarding this matter ?
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.
Writing to tables created by regular users on MSSQL2005
I have users creating tables through an application, I gave them ddl_admin, datareader, datawriter. They can create tables but cannot insert/update data (to their own tables), I cannot insert data either using Access or any other application to those tables created by them (under dbo schema) Is there something I am missing with permissions? Thank you very much
I have recently upgraded to SQL2014 on Win2012. The Access front end program works fine.
But, previously created Excel reports with built in MS Queries now fail with the above error for users with MS 2013. The queries still work for users still using MS 2007.
I also cannot create any new queries and get the same error message. If I log on as myself on the domain to another PC with 2007 installed it works fine, so I don't think it is anything to do with AD groups or permissions.
Hi Folks, I have two database. database A, and database B. now I want to insert some recordrs from the table of database A to some table of database B, using "insert" command. Please help me out in this regard.
Need to insert .wav or mp3 file into sql server.I need to store maximum of 2 or 3 min of file into the database.which format would the best storing as .wav or .mp3.I think storing mp3 in blob data would be best.Pl. give suggestion which would be of much help to me.
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?
hey everyone,I have created two tables in an sql server database. I have a check box in the table 1, and when it is checked, I want to insert that particular record into table 2. (By the way I am using a datagrid) The problem is when I click the check on the particular record I want inserted, and click update, the system copies the record twice instead of once. When I look into table 2, I end up having two of the same records. Can anyone help me.
I am using visual devloper express, and i have been following allow in the "starter videos". for lesson 8, the example worked fine, but when i try to replicate the example with a SQL database (external one) when I am configuring the formView, and i try to click the advanced tab under 'Advanced SQL Generation Options", I do not have the abilty to check the 2 boxes for generate insert, update, delete statements, etc (they are greyed out). i have an asp page that has the same connection as this page and i am able to insert a record, so i am sure it's not a permission thing... I don't understand what I am doing wrong here... a plain old asp coded page inserts records into this table in the same database, but I am unable to check the boxes for "generate insert" etrc, and the error I get on the page itself is Inserting is not supported by data source 'SqlDataSource1' unless InsertCommand is specified. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NotSupportedException: Inserting is not supported by data source 'SqlDataSource1' unless InsertCommand is specified.
I try to make something or set an option, which would generate next values of the id of some table (id is primary key) while inserting a row to the table. I used once a sequence for Oracle database and wonder if there is something similar in .Net for "standard" database (Add new item -> SQL Database). I'm using SqlDataSources.Is Repeater a component that would be useful here? Or shall i write a function that would generate ids manually?Thanks in advance
Hello all, I'm very new to web development and I have hit a snag in my project that I am hoping someone can help me with. I am trying to allow users to upload photos into my database using the formview control and the fileupload control. I have specified the data type as image, but when I try to upload a photo or just pass a null value I get the following error. Operand type clash: sql_variant is incompatible with image Does anyone know why this might be? Thanks very much. Matt Downey
Hello everyone, I am having some problems inserting some data into a database - I have been stuck on this almost all day now and I'm almost pulling my hair out! I'm quite new to ASP.net and have been thrown in the deep end with this assignment... And advice or help would be greatly appreciated. Thanks. Protected Sub CreateUserWizard1_CreatedUser1(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.CreatedUser
'Assign new user to role of Applicant Roles.AddUserToRole(CreateUserWizard1.UserName, "Applicant")
'Create Connection String
UserName = CreateUserWizard1.UserName
Dim DBConn As New SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|ASPNETDB.MDF;Integrated Security=True;User Instance=True")
Dim DBCmd As New SqlCommand
DBConn.Open()
'Add Insert Statement
DBCmd = New SqlCommand("INSERT INTO aspnet_Users(MobileAlias) VALUES (@Applicant) WHERE UserName=@UserName", DBConn)
Incorrect syntax near the keyword 'WHERE'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'.
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.
I have a page called 'upload.vb', which is the code for a file upload project I am working on. I am trying to write the filenames to an SQL database that I have built, but I keep getting this error: Compiler Error Message: BC30201: Expression expected. It doesn't seem to like the @ on line 46 in the VALUES part of my INSERT statement. Can anybody shed any light on this. Thanks. 1 Imports System 2 Imports System.Data 3 Imports System.Configuration 4 Imports System.Web 5 Imports System.Web.Security 6 Imports System.Web.UI 7 Imports System.Web.UI.WebControls 8 Imports System.Web.UI.WebControls.WebParts 9 Imports System.Web.UI.HtmlControls 10 Imports System.IO 11 Imports System.Data.SqlClient 12 13 ''' <summary> 14 ''' Upload handler for uploading files. 15 ''' </summary> 16 Public Class Upload 17 Implements IHttpHandler, IReadOnlySessionState 18 19 Public Sub New() 20 End Sub 21 22 #Region "IHttpHandler Members" 23 24 Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable 25 Get 26 Return True 27 End Get 28 End Property 29 30 31 32 Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest 33 34 If context.Request.Files.Count > 0 Then 35 ' get the applications path 36 Dim tempFile As String = context.Request.PhysicalApplicationPath 37 ' loop through all the uploaded files 38 Dim j As Integer = 0 39 While j < context.Request.Files.Count 40 ' get the current file 41 Dim uploadFile As HttpPostedFile = context.Request.Files(j) 42 ' if there was a file uploded 43 If uploadFile.ContentLength > 0 Then 44 45 uploadFile.SaveAs(String.Format("{0}{1}{2}", tempFile, "Uploads", uploadFile.FileName)) 46 SqlDataSource.InsertCommand = "INSERT INTO tblDocuments(TheFileName) VALUES ('" & @TheFileName & "')" 47 48 End If 49 System.Math.Max(System.Threading.Interlocked.Increment(j), j - 1) 50 End While 51 End If 52 ' Used as a fix for a bug in mac flash player that makes the 53 ' onComplete event not fire 54 HttpContext.Current.Response.Write(" ") 55 End Sub 56 #End Region 57 58 End Class
hi is it possible to insert a session into a database E.G. i'm sure this code is fine but i duno why its not inserting the session into the database the form parameter is going in fine but the session aian't UserName.Text = Session("User")<asp:sqldatasource id="SqlDataSource1" runat="server" selectcommand="SELECT Party.Party FROM Party" insertcommand="INSERT INTO Vote(UserName,Vote) VALUES (User,Party)" ConnectionString="<%$ ConnectionStrings:VotingConnectionString %>" ProviderName="<%$ ConnectionStrings:VotingConnectionString.ProviderName %>"> <InsertParameters> <asp:SessionParameter Name="User" Type="String" SessionField="User" /> <asp:FormParameter Name="Party" Type="String" FormField="PartyList" /> </InsertParameters> </asp:sqldatasource>
ok i've got several pages that insert with no problem but this one is giving me fits. The query it's generated works, because i've plugged it into the database through access and it worked. here is my code what am i doing wrong? It opens the connection and then gets to the executeNonQuery and doesn't do it not sure why.
Dim sqlInsert As String Dim ssn As String Dim ssnDash As String Dim mma As String Dim position As String Dim subject As String Dim mmaCheck As String Dim subjectCheck As String Dim bothCheck As String Dim otherCheck As String Dim flag As Boolean = False Dim added As Boolean = False
Try If txtSSN.Text <> "" Then ssn = txtSSN.Text ssnDash = ssn.Substring(0, 3) & "-" & ssn.Substring(3, 2) & "-" & ssn.Substring(5, 4) End If
mma = dlMMA.SelectedValue.ToString position = dlPosition.SelectedValue.ToString subject = dlMajor.SelectedValue.ToString
Catch ex As Exception Response.Write("Please fill in all fields") End Try
otherCheck = mma & subject
Dim dr As DataRow
For Each dr In dsMajor.Tables("List_Of_MMA").Rows If mma = dr.Item("mma").ToString And subject = dr.Item("Subject").ToString Then mmaCheck = dr.Item("MMA").ToString subjectCheck = dr.Item("Subject").ToString flag = True bothCheck = mmaCheck & subjectCheck End If Next
If flag = False Then Response.Write("Didn't Work") Else sqlInsert = "INSERT INTO Student_Major(SSN, MMA, Subject, Position) Values('" sqlInsert += ssnDash & "','" sqlInsert += mmaCheck & "','" sqlInsert += subjectCheck & "','" sqlInsert += position & "')"
Dim com As OleDbCommand = New OleDbCommand(sqlInsert, myConnection) Try myConnection.Open() com.ExecuteNonQuery()
added = True Catch ex As Exception Response.Write(sqlInsert) Finally myConnection.Close() End Try
'If added = True Then Response.Write("New Major, Minor, or Area added: " & subject) 'End If End If
the problem is that in location_name, I am allowing ' as a valid character. Can anyone help me with this. everytime i execute my statement is truncated because of '.
Hi,Recently I was asked to insert images into the database as a part of my module,can someone help me out on this, How can I insert images and retrieve the same from databaseSandhya
I am currently trying to import CSV files into a sql database table. While I have managed to get the majority of the import to work, some of the records are failing to import due validation errors. What I would like to know is, is it possible to separate out the records that failed to import from the CSV file? The CSV file is quite large so I am unable to locate these records by hand. Thanks
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.
Hi, how do I go about inserting image into the SQL Compact Edition Database? This is something similar to the Photo Column in the Employees Table in Northwind Database.
I have set the Photo Column properties as 'image', but all that appears is a white icon with a red x. How do I change this to my own image?
I have a question about new record insertion. I have a SQL Database that I have cofigured as a publisher for a mobile database. I want to be able using the PDA to insert new Customers and synchronize the CE database with the SQL DB. But I encounter a problem with the column field rowguid that SQL inserts as a unique indentifier during the publication. It cannot accept null values and I can't insert a value using the keyboard since the value is generated by SQL.
So my impression is that you cannot use PDA to insert new records, only to update old ones. Is that true or I miss something??
Here's the error I get trying to run the code posted below..."Prepared statement '(@datestamp datetime,@PrevValue real,@NewValue real,@IPaddress r' expects parameter @datestamp, which was not supplied."I've tried it without the quotes around the DateTime.Now and also adding the # around them. Without the quotes, I do get a different error because it doesn't like the spaces in the DateTime text. Also, the datestamp data in the database is formatted as a datetime (MS SQL Server 2005).Here's my code:Private Sub UpdateRefresh()UpdateConnection.Open()UpdateDataAdapter.InsertCommand.CommandText = "INSERT INTO dbo.tbDeploy(datestamp," & _"PrevValue, NewValue, IPaddress, HighCapability, LowCapability, Share) VALUES" & _"('" & DateTime.Now & "', '" & lblCurrent.Text & "', '" & lblCurrent.Text & _"', '" & lblIP.Text & "', '" & lblHigh.Text & "', '" & lblLow.Text & "', '" & lblShare.Text & "')"UpdateDataAdapter.InsertCommand.ExecuteNonQuery()UpdateConnection.Close()End Sub
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...
Hello, Could someone give me the code for inserting an image into the database. I have the field declared in my table. And the image needs a type value because it receives the message "nvarchar is incompatible with image"
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
Hello, I inserted a .csv file into the database using DTS and it get inserted successfully. But my problem is, the csv file contains the datas that has double quotes on it (eg: 1/2" iron rod, 3/4" wooden rod). When I checked the inserted datas, it was inserted as "1/2" iron rod, 3/4"""," 3/4" wooden rod"". How do I eliminate these additional double quotes. Raviraj Danasekaran