SQL Server Fields And Sqlparameters
Nov 7, 2005
I am setting up a database and I would like to insert fields using sqlparameters into the database. What I need to know is the relation between sqlparameter size and db field 'length' field.IE: In the database does the 'length' field indicate bits? (which means that you have to convert parameter to bytes?)and what does the 8 refer to below?<CODE>Dim Param2 As New SqlClient.SqlParameter("@flTest", SqlDbType.VarChar)Param2.Size = 8</CODE>Thanks,Joe
View 1 Replies
ADVERTISEMENT
Apr 11, 2008
lets say i have a stored procedure (for insert command) which i am calling in my code to execute. The user provided data is being stored in a array. My class takes the stored procedure name and also takes parameters name and types. Is there any way to loop through the parameters, (various columns in the table which is of diffrent data type ie varchar, int, etc). How to implement it?
View 1 Replies
View Related
Mar 22, 2006
Hi:I'm trying to pass a parameter to the store procedure below:CREATE PROC get_cat(@lang varchar(2))ASif(@lang="es") SELECT [cod_cat], [nombre] FROM [myuser].[Tbl_cat]if(@lang="en") SELECT [cod_cat], [nombre_en] FROM [myuser].[Tbl_cat]GOand on the .cs Codebehind file I'm using using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;namespace links_us{public class faqs : System.Web.UI.Page { protected System.Data.SqlClient.SqlConnection sqlConnFaqs; protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapFaqs; protected System.Data.SqlClient.SqlCommand sqlSelectCommand1; protected System.Data.SqlClient.SqlParameter Params; protected System.Web.UI.WebControls.Repeater RepeaterFaq; protected links_us.DataSetFaq dataSetFaq; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here Params = new System.Data.SqlClient.SqlParameter("@lang", SqlDbType.VarChar, 2); Params.Value = "en"; Params.Direction = ParameterDirection.Output; sqlDataAdapFaqs.Fill(dataSetFaq, "get_cat"); RepeaterFaq.DataBind(); } ........I´m getting this error:System.Data.SqlClient.SqlException: Procedure 'get_cat' expects parameter '@lang', which was not supplied.What´s wrong?Thanks in advance
View 2 Replies
View Related
Dec 31, 2006
Anyone can help me why is this not working?
My function is
public void updateSupplierInformation(string FirstLetter, string Vendor, string SegmentTeam, string VendorRank, string ScrubOwner)
{
SqlCommand myCommand = new SqlCommand("sp_LAST_UpdateSupplier", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myConnection.Open();
SqlParameter myParam;
myParam = myCommand.Parameters.Add(new SqlParameter("@FirstLetterS", SqlDbType.VarChar, 1));
myParam.Direction = ParameterDirection.Input;
myParam.Value = FirstLetter;
myParam = myCommand.Parameters.Add(new SqlParameter("@VendorS", SqlDbType.VarChar, 30));
myParam.Direction = ParameterDirection.Input;
myParam.Value = Vendor;
myParam = myCommand.Parameters.Add(new SqlParameter("@SegTeamS", SqlDbType.VarChar, 30));
myParam.Direction = ParameterDirection.Input;
myParam.Value = SegmentTeam;
myParam = myCommand.Parameters.Add(new SqlParameter("@VendorRankS", SqlDbType.VarChar, 30));
myParam.Direction = ParameterDirection.Input;
myParam.Value = VendorRank;
myParam = myCommand.Parameters.Add(new SqlParameter("@ScrubOwnerS", SqlDbType.VarChar, 30));
myParam.Direction = ParameterDirection.Input;
myParam.Value = ScrubOwner;
int i =myCommand.ExecuteNonQuery();
myConnection.Close();
}
My Stored procedure is:
ALTER PROCEDURE sp_LAST_UpdateSupplier
@FirstLetterS varchar(1),
@VendorS varchar(30),
@SegTeamS varchar(30),
@VendorRankS varchar(30),
@ScrubOwnerS varchar(30)
AS
UPDATE [gntm_user].LAST_Supplier_Ownership
SET First_Letter =@FirstLetterS,Seg_Team =@SegTeamS,Vendor_Rank =@VendorRankS,
Scrub_Owner =@ScrubOwnerS
WHERE Vendor=@VendorS
RETURN
When I debug on any of the myParam value it displays "@FirstLetterS,@VendorS" etc. not the value which is being passed in the function which is FirstLetter,Vendor.
Can anyone help me on this please? Thanks in advance
View 2 Replies
View Related
May 13, 2004
Hi there!
I was trying to dynamically load a custom WebControl and display it into my WebFrom.
WebControl is loaded by:
System.Reflection.Assembly assembly = System.Reflection.Assembly.Load("myAssemblyName");
Control module = (Control)Activator.CreateInstance( assembly.GetType("myClassName") );
ModulePlaceHolder.Controls.Add(module);
This is working fine. Assembly is loaded and WebControl is created.
But as my Custom WebControl tries to access SQL Server database, i get a "Must declare the variable '@id'" while executing an ExecuteScalar() from a SqlCommand.
Code in my WebControl was perferctly functioning before converting it from a UserControl (.ascx) to Custom WebControl. Parameter '@id' is correctly declared in my query. If i don't use SqlParameters, everithing works fine...
Any ideas??
Thank you so much!!!
Bye!
View 2 Replies
View Related
Feb 20, 2008
How can I create a Table whose one field will be 'tableid INT IDENTITY(1,1)' and other fields will be the fields from the table "ashu".
can this be possible in SQL Server without explicitly writing the"ashu" table's fields name.
View 8 Replies
View Related
May 7, 2008
In my site, when a user registers, I need to create rows in additional tables besides aspnet_Users. So, I need to be able to pass the generated userId guid to subsequent SqlCommands. I'm having a terrible time with this. What's the correct way to set up a SqlParameter so that it will accept a guid? I keep getting this error: "Conversion failed when converting from a character string to uniqueidentifier."
I've tried creating the parameter both with and without a SqlDbType.
cmd.Parameters.AddWithValue(paramName, guid);
and
SqlParameter p = new SqlParameter(paramName);p.SqlDbType = SqlDbType.Guid;cmd.Parameters.Add(p);
and I get the same error either way.
Driving me nuts! Any help appreciated.
View 1 Replies
View Related
Jan 28, 2008
I have just started using SQL Server reporting services and am stuck with creating subreports.
I have a added a sub report to the main report. When I right click on the sub report, go to properties -> Parameters, and click on the dropdown for Parameter Value, I see all Sum and Count fields but not the data fields.
For example, In the dropdownlist for the Parameter value, I see Sum(Fields!TASK_ID.Value, "AppTest"), Count(Fields!TASK_NAME.Value, "CammpTest") but not Fields!TASK_NAME.Value, Fields!TASK_ID.Value which are the fields retrieved from the dataset assigned to the subreport.
When I manually change the parameter value to Fields!TASK_ID.Value, and try to preview the report, I get Error: Subreport could not be shown. I have no idea what the underlying issue is but am guessing that it's because the field - Fields!TASK_ID.Value is not in the dropdown but am trying to link the main report and sub report with this field.
Am I missing something here? Any help is appreciated.
Thanks,
Sirisha
View 3 Replies
View Related
Jan 26, 2008
sir
I have got this error message to establish connction with recordset vb .net, Can you please rectify this
Too many arguments to 'Public Overridable ReadOnly Default Property Fields() As ADODB.Fields'
my code like this
rs = New ADODB.Recordset
rs.Open("Select * from UserLogin where userid='" & txtUserName.Text & "'", gstrDB, DB.CursorTypeEnum.adOpenStatic)
If txtUserName.Text = rs.Fields.Append(userid) Then
MsgBox("OK", MsgBoxStyle.OKOnly, "Confirmation")
End If
thanks
View 1 Replies
View Related
Jul 23, 2005
Hello !I'm trying to update one table field with another table searched firstdate record.getting some problem.If anyone have experience similar thing or have any idea about it,please guide.Sample case is given below.Thanks in adv.T.S.Negi--Sample caseDROP TABLE TEST1DROP TABLE TEST2CREATE TABLE TEST1(CUST_CD VARCHAR(10),BOOKING_DATE DATETIME,BOOKPHONE_NO VARCHAR(10))CREATE TABLE TEST2(CUST_CD VARCHAR(10),ENTRY_DATE DATETIME,FIRSTPHONE_NO VARCHAR(10))DELETE FROM TEST1INSERT INTO TEST1 VALUES('C1',GETDATE()+5,'11111111')INSERT INTO TEST1 VALUES('C1',GETDATE()+10,'22222222')INSERT INTO TEST1 VALUES('C1',GETDATE()+15,'44444444')INSERT INTO TEST1 VALUES('C1',GETDATE()+16,'33333333')DELETE FROM TEST2INSERT INTO TEST2 VALUES('C1',GETDATE(),'')INSERT INTO TEST2 VALUES('C1',GETDATE()+2,'')INSERT INTO TEST2 VALUES('C1',GETDATE()+11,'')INSERT INTO TEST2 VALUES('C1',GETDATE()+12,'')--SELECT * FROM TEST1--SELECT * FROM TEST2/*Sample dataTEST1CUST_CD BOOKING_DATE BOOKPHONE_NOC12005-04-08 21:46:47.78011111111C12005-04-13 21:46:47.78022222222C12005-04-18 21:46:47.78044444444C12005-04-19 21:46:47.78033333333TEST2CUST_CD ENTRY_DATE FIRSTPHONE_NOC12005-04-03 21:46:47.800C12005-04-05 21:46:47.800C12005-04-14 21:46:47.800C12005-04-15 21:46:47.800DESIRED RESULTCUST_CD ENTRY_DATE FIRSTPHONE_NOC12005-04-03 21:46:47.80011111111C12005-04-05 21:46:47.80011111111C12005-04-14 21:46:47.80044444444C12005-04-15 21:46:47.80044444444*/
View 3 Replies
View Related
Jul 2, 2015
I am using MS SQL 2012. I have a table that contains all the data that I need, but I need to summarize the data and also add up decimal fields while at it. Then I need a total of those added decimal fields. My data is like this:
I have Providers, a unique ID that Providers will have multiples of, and then decimal fields. Here are my fields:
ID, provider_name, uniq_id, total_spent, total_earned
Here is sample data:
1, Harbor, A07B8, 500.00, 1200.00
2, Harbor, A07B8, 400.00, 800.00
3, Harbor, B01C8, 600.00, 700.00
4, Harbor, B01C8, 300.00, 1100,00
5, LifeLine, L01D8, 700.00, 1300.00
6, LifeLine, L01D8, 200.00, 800.00
I need the results to be just 3 lines:
Harbor, A07B8, 900.00, 2000.00
Harbor, B01C8, 900.00, 1800.00
LifeLine, L01D8, 900.00, 2100.00
But then I would need the totals for the Provider, so:
Harbor, 1800.00, 3800.00
View 3 Replies
View Related
Jul 20, 2005
I would like to search a table for a phrase, or for a partial phrase,eg on table product - for name or description, or name + descprition.How does one say select * from product where name + description like%phrase%or contains phraseCurrently I can get where name, or where descriotion like %phrase%,eg, where name like krups, or where description like coffee makerBut if I search for where name like %krups coffee maker% i get noresults. krups is in the name field, coffee maker is in thedescription field.Thanks,-M
View 1 Replies
View Related
Jun 30, 2000
Pardon me if this question is too elementary. I am trying to create a trigger that will cause certain datafields to be updated with values from other data fields in the same row when a certain column, created specifically to fire the trigger, is updated. The purpose of this is to reduce data entry by field personnel.I think I have the create trigger statement correct, but I'm a little confused on the update statement.
In a nutshell, how can I write something like:
UPDATE "TABLENAME"
SET DATAFIELD1 = DATAFIELD2
WHERE RECORDNUMBER = (THE SAME RECORD NUMBER)
I do know that I have to ensure that sp_dboption Recursive Triggers value is set to false, thanks.
View 2 Replies
View Related
Jul 31, 2013
I have a list of items in one table and a field (pageName) in another table that may contain one of the aforementioned items somewhere within that field. There is no fixed position within the field where the itemNo may be so I can't just use SUBSTRING(pageName,2,5) in(select itemNo from tblItem).
Logically, it's like I need to combine IN and LIKE: select pageName where pageName LIKE IN %select itemNo from tblitemNo%..LIKE can only handle one comparison string.
View 5 Replies
View Related
Jan 21, 2008
Hi people
My users are having troubles with link to default drillthrough report when reports are exported to excel (they REALLY don't like this behavior ), so I decided set all of them disabled in report model, this work fine, but calculated field in reports has this drillthrough link.
Let me show you the situation. Entity Product has an UnitaryCost field, I set the EnableDrillthrough Property in False so when I export a report with this field, no link is shown.
But if I create in the report a calculated field Round(UnitaryCost) this field has a Drillthrough Link
Is this the standard and expected behavior? or its simply a BUG?
Have I done something wrong in my model? and in this case, How I can correct this?
regards.
Julio Diaz.
View 1 Replies
View Related
Jul 5, 2000
I need to set up a table within my customer's database capable of storing
articles written in English, Japanese, Korean, and Dutch. I can't seem to
get SQL Server set up correctly to run this if anyone has any tips or
pointers I would really appreciate any help to be had. After setting the
fields to nVarChar when unicode text is inputted all I get are '????'
stored within the field and outputted through asp.
Please Help I have been all over the place tryign to gather information on
this subject.
-Richard S. Hale
ASP Developer, Medi-Specialty.com
View 2 Replies
View Related
Mar 16, 2006
The Text datatype can hold several million characters
The size of a record can be no more than 8 KB in normal data.
Created a table with one text field. For some reason can only store 1K of data into it. Even if the 8K limit was a factor (which it shouldn't for a text field) I cannot add more than 1K of data into my text field. 1023 characters to be exact.
Why is SQL Server 2000 doing this and more importantly how to resolve?
View 8 Replies
View Related
Jul 20, 2005
Does anyone know if Microsoft is planning to add a DATE only data typeto SQLServer.I know that you could use a datetime and convert/cast or use datepartto compare, but this can be tedious and error prone.What is the recommended way to compare date-only fields?eg if convert(char(11), @date_field) = convert(getdate(), @date_field)-- do something??
View 3 Replies
View Related
Feb 28, 2006
I am new to using SQL Server and need some help creating lookup fields if it is possible.
I use the lookup wizard to create lookup fields in access. Can you do the same in SQL?
I have successfully created relationships in SQL but I want to lookup the related fields during data entry like in Access with a dropdown box with the available options.
View 3 Replies
View Related
Oct 12, 2006
I feel sure that this is a very naive question, but it is freeky me out that I can solve it. With SQL server what is the easiest way to make a field other than the Primary key unique?Would appreciate help with this. ThanksPaul
View 3 Replies
View Related
Apr 13, 2007
when inserting or updating fields in sql server and the field is blank sql still adds several spaces into the field. Then if I try to check whether a field is empty or not for display I get incorrect results because fields that should be empty have 2 or 3 spaces in them instead and therefor aren't selected as being empty. Is there any way around this? to force the fields to be saved as blanks or null?
View 3 Replies
View Related
May 13, 1999
Most of the tables in my database are implemented with IDENTITY columns as the primary key.
When an INSERT from my application is attempted, sometimes I get an error returned stating that insert
cannot be done because of duplicate key value. If I try the INSERT again, sometimes it works(??). Of course,
DBCC CHECKIDENT resets the identity value if trying the INSERT again doesn't work. Then sometime a little later, the problem happens again.
Is there anything I can do other than placing into my application code the execution of dbcc checkident
anytime I want to do an insert to prevent the error? By the way, DBCC CHECKDB revealed no problems.
HELP!
View 3 Replies
View Related
Feb 15, 2004
Hi
This may seem amazing and a stupid question but:
Consider there is a parent table A and child table B and we want to write a query that has some fields from A and a calculated field which indicates whether A has any child record in B or not. The Value 1 means Yes and 0 means No. Has anybody an idea to write this in SQL Server?
View 2 Replies
View Related
Nov 15, 2007
I want to select all the fields from just one table
This is what i have and i am having trouble selecting all the fields
select * from ace_users
where chdata EXISTS
(select chdata, count(chserialnum)
from ace_users
group by chdata
having count(chserialnum)> 1)
Exists and IN does not work.
View 3 Replies
View Related
Sep 21, 2005
Greetings,I used to do this kind of query in Ingres, where I concatenate(+)various fields as one field and search accordingly.Is there an equivalent method in SQL server ?SELECT a.rsrcid,a.rsrchqnumber,c.perslastname,c.persfirst name,b.asgtid,b.asgtactualstartdate,b.asgtactualenddate ,CASE b.enumstateWHEN '2' THEN 'Running'WHEN '3' THEN 'Cancelled'WHEN '4' THEN 'Closed'WHEN '6' THEN 'Open'END AS statusFROM pblocal.dbo.resources aINNER JOIN pblocal.dbo.assignments b ON b.asgtrsrcguid = a.rsrcguidINNER JOIN pblocal.dbo.persons c ON c.persguid = a.rsrcpersguidWHERE a.rsrcid+a.rsrchqnumber+c.perslastname+c.persfirst name not in(SELECT e.rsrcid+e.rsrchqnumber+g.perslastname+g.persfirst nameFROM dtlocal.dbo.resources eINNER JOIN dtlocal.dbo.assignments f ON f.asgtrsrcguid = e.rsrcguidINNER JOIN dtlocal.dbo.users h ON h.userguid = e.rsrcuserguidINNER JOIN dtlocal.dbo.persons g ON g.persguid = h.userpersguid)
View 6 Replies
View Related
Mar 7, 2008
Is there a way to make some fields in reporting services report editable?
View 3 Replies
View Related
Apr 11, 2014
Create Table #Temp (ID int not null primary Key, Name varchar(25) not null, DOB datetime not null, Sex char(1), Race char(1), Height int, Weight int)
insert #Temp
select 1, 'Kenneth', '1963-02-26 00:00:00.000', 'M','C', 516, 160
union
select 2, 'Kenneth', '1963-02-26 00:00:00.000', NULL,NULL, NULL, NULL
union
select 3, 'William', '1962-06-28 00:00:00.000', 'M','C', 600, 223
[Code] .....
/* Expecting Output */
select 1 as ID, 'Kenneth' as Name, '1963-02-26 00:00:00.000' as DOB, 'M' as Sex,'C' as Race, 516 as Height, 160 as Weight
union
select 2, 'Kenneth', '1963-02-26 00:00:00.000', 'M','C', 516, 160
union
select 3, 'William', '1962-06-28 00:00:00.000', 'M','C', 600, 223
union
[Code] .....
View 5 Replies
View Related
May 30, 2014
I have a table where one of the fields contains XML as in the following. Is there an SQL update statement that can change any occurrences of timezoneIdfrom 0 to 1, and timezone from America/New_York to America/Chicago and time to time - 1 hour?
<scheduleitem><schedule><frequency><weekly weeklyInterval="1"><WED/></weekly></frequency><startDate>2008-08-05</startDate><time>22:30:00</time><timezoneId>0</timezoneId><timezone>America/New_York</timezone></schedule></scheduleitem>
After the query is run, rows like the above would be changed to
<scheduleitem><schedule><frequency><weekly weeklyInterval="1"><WED/></weekly></frequency><startDate>2008-08-05</startDate><time>21:30:00</time><timezoneId>1</timezoneId><timezone>America/Chicago</timezone></schedule></scheduleitem>
View 6 Replies
View Related
Sep 15, 2015
Trying to get the max count grouped by all the fields. All the fields are the same, but trying to get the location for each physician that has the largest number of patients.
if the output for the sql below is:
101, 10, Jon, Smith, MD, Ortho, OR, 15
101, 10, Jon, Smith, MD Ortho, 1, 12
101, 10, Jon, Smith, MD, Ortho, 2, 10
24, 3, Mike, Jones, MD, Neuro, OR, 21
24, 3, Mike, Jones, MD, Neuro, 2, 43
I'd like to have the query rewritten so the results are as:
101, 10, Jon, Smith, MD, Ortho, OR, 15
24, 3, Mike, Jones, MD, Neuro, 2, 43
SELECT
a.attendingmdkey,e.[provider id],e.[first name],e.[last name],e.title,e.specialty,l.locationname,count(a.accountid) as Count
FROM accounts a
left outer join location l on l.locationid=a.locationid
left outer join providers e on e.[ProviderID]=a.attendingmdkey
where a.dischargedate>='2014-12-01' and a.dischargedate<'2015-01-01'
and a.divisioncode in ('1','2','$')
group by a.AttendingMdKey,e.[provider id],e.[first name],e.[last name],e.title,e.Specialty,l.locationname
order by a.AttendingMdKey
View 3 Replies
View Related
Jul 20, 2005
I'm running SQL Server 2K (sp3a) and when I run the following query (inquery analyzer):SELECT id, LEN(ForeignWord) as Length, ForeignWordFROM WordsWHERE Language ='Thai' and LEN(ForeignWord) > 300ORDER BY Length descI receive the following results:id Length ForeignWord------- ----------- -----------34756 445 เ#...truncated at 25534839 412 เ$...truncated at 25537613 350 โ#...truncated at 25537808 315 โ#...truncated at 25538140 315 โ#...truncated at 255(The ForeignWord field is defined as varchar(1000))Note that even though the server says that the lengths are in excess of255 characters, the results are all truncated at 255 characters.I read that SQL Server 6.5 and 7.0 had some issues related to nativeaccess versus OleDb or ODBC, but this is Server 2K patched with thelatest updates.Any idea why my varchar fields are being truncated?-- RickHere is my table definition:CREATE TABLE [Words] ([ID] [bigint] IDENTITY (1, 1) NOT NULL ,[Language] [varchar] (50) NOT NULL ,[Module] [int] NOT NULL ,[Lesson] [int] NOT NULL ,[EnglishWord] [varchar] (1000) NOT NULL ,[ForeignWord] [varchar] (1000) NOT NULL ,[Note] [varchar] (2000) NULL ,[Military] [tinyint] NOT NULL CONSTRAINT [DF_Table1_Military]DEFAULT (0),[Supplemental] [tinyint] NOT NULL CONSTRAINT [DF_Table1_Supplemental] DEFAULT (0),[SoundFileName] [varchar] (1000) NULL)
View 4 Replies
View Related
Aug 9, 2006
Hi,
I'm trying to write some SQL which will give me the following result from the table below..
Currently I can do each of the PRICEx fields in a seperate query then join the results together. I do this by getting the MAX(Date) WHERE PRICEx IS NOT NULL then using that date to get PRICEx, and then repeat until I've done all the PRICE fields.
This is acceptable for a small selection, but for a large selection this can get quite slow. I was just wondering if there is there a way to do this in one single SQL without having to join the table to itself 3 times (for all 3 PRICE fields)
Source Table:
ProductID
MarketID
Date
PRICE1
PRICE2
PRICE3
1
2
1/01/2006
2.45
3.4
2.97
1
2
2/01/2006
2.51
3.5
NULL
1
2
3/01/2006
NULL
3.6
NULL
1
2
4/01/2006
NULL
NULL
NULL
Result:
ProductID
MarketID
PRICE1
PRICE2
PRICE3
1
2
2.51
3.6
2.97
Thanks,
Victor.
View 14 Replies
View Related
Mar 26, 2008
I am developing a asp.net app and I have a long, very long list of data fields.
The values of the data fields have to be saved to a SQL database. The list is so long that it a pain in the ass to have to write all the code even to declare an object and all its properties by hand. So...
I made a list of all the field names and types and load it all up in an array. Then I wrote a bunch of macros to write all the properties one by one with the corredt type for the object I needed to create instead of doing it all one by one by hand.
I want to do the same thing with the Database. I dont want to have to hand define all the fiedls 1 by 1 by hand in the IDE. I want to write a simple macro, a loop theat loops thru my array and creates a field with the field name and type that it says in the array.
Simple enough.. Now I have the table defined already since that was simple enough. It is the 200 ++ fields that I dont wanna do.
So, please what is the code I need (in VB) to create 1 simple field in an existing table. Say the table is called "Table1" in the database "Database1" and the field I want is to be called "Field1" and to be 250 chr string..... ???
Thank you Marc
View 3 Replies
View Related
Nov 30, 2005
Hi, I'm new around here and am stumped. I have created a form where I submit the information into a SQL Server 2000 table. When I submit the information through the form, only the first character of each field populates inside of the SQL table. This happens for every field except for two, zip and comments. The zip field is numeric and the comments field is text. All the other fields are varchar fields; and these are the fields with the problems. I have attempted to change the data type to text, but that did not work either. I am doing this through a stored procedure I created. Here is the asp code:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
Protected WithEvents txtAddress1 As System.Web.UI.WebControls.TextBox
Protected WithEvents txtAddress2 As System.Web.UI.WebControls.TextBox
Protected WithEvents txtCity As System.Web.UI.WebControls.TextBox
Protected WithEvents txtZip As System.Web.UI.WebControls.TextBox
Protected WithEvents txtEmail As System.Web.UI.WebControls.TextBox
Protected WithEvents txtPhone As System.Web.UI.WebControls.TextBox
Protected WithEvents txtComments As System.Web.UI.WebControls.TextBox
Protected WithEvents ddlState As System.Web.UI.WebControls.DropDownList
Protected WithEvents ddlGift1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents ddlGift2 As System.Web.UI.WebControls.DropDownList
Protected WithEvents ddlGift3 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
Protected WithEvents SqlCommand1 As System.Data.SqlClient.SqlCommand
Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()
Me.SqlCommand1 = New System.Data.SqlClient.SqlCommand()
'
'SqlConnection1
'
Me.SqlConnection1.ConnectionString = "data source=NDAVENPORT2;initial catalog=Bluestreak;integrated security=SSPI;persi" & _
"st security info=False;workstation id=NDAVENPORT2;packet size=4096"
'
'SqlCommand1
'
Me.SqlCommand1.CommandText = "dbo.[InsertFreeOrders]"
Me.SqlCommand1.CommandType = System.Data.CommandType.StoredProcedure
Me.SqlCommand1.Connection = Me.SqlConnection1
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(10, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@firstname", System.Data.SqlDbType.VarChar, 50))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@lastname", System.Data.SqlDbType.VarChar, 50))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@address1", System.Data.SqlDbType.VarChar, 100))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@address2", System.Data.SqlDbType.VarChar, 100))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@city", System.Data.SqlDbType.VarChar, 50))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@state", System.Data.SqlDbType.VarChar, 50))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@zip", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, False, CType(18, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@email", System.Data.SqlDbType.VarChar, 50))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@phone", System.Data.SqlDbType.VarChar, 50))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@item1", System.Data.SqlDbType.VarChar, 50))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@item2", System.Data.SqlDbType.VarChar, 50))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@item3", System.Data.SqlDbType.VarChar, 50))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@comments", System.Data.SqlDbType.VarChar, 2147483647))
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If IsValid Then
SqlCommand1.Parameters("@firstname").Value = txtFirstName.Text
SqlCommand1.Parameters("@lastname").Value = txtLastName.Text
SqlCommand1.Parameters("@address1").Value = txtAddress1.Text
SqlCommand1.Parameters("@address2").Value = txtAddress2.Text
SqlCommand1.Parameters("@city").Value = txtCity.Text
SqlCommand1.Parameters("@state").Value = ddlState.SelectedItem.Text
SqlCommand1.Parameters("@zip").Value = txtZip.Text
SqlCommand1.Parameters("@email").Value = txtEmail.Text
SqlCommand1.Parameters("@phone").Value = txtPhone.Text
SqlCommand1.Parameters("@item1").Value = ddlGift1.SelectedItem.Text
SqlCommand1.Parameters("@item2").Value = ddlGift2.SelectedItem.Text
SqlCommand1.Parameters("@item3").Value = ddlGift3.SelectedItem.Text
SqlCommand1.Parameters("@comments").Value = txtComments.Text
SqlConnection1.Open()
SqlCommand1.ExecuteNonQuery()
SqlConnection1.Close()
Response.Redirect("Success.aspx")
End If
End Sub
End ClassMy stored procedure looks like this:CREATE PROCEDURE dbo.InsertFreeOrders ( @firstname varchar( 50 ), @lastname varchar( 50 ), @address1 varchar( 100 ), @address2 varchar( 100 ), @city varchar( 50 ), @state varchar( 50 ), @zip numeric, @email varchar( 50 ), @phone varchar( 50 ), @item1 varchar( 50 ), @item2 varchar( 50 ), @item3 varchar( 50 ), @comments text )ASInsert FreeOrders ( o_first_name, o_last_name, o_address_1, o_address_2, o_city, o_state, o_zip, o_email, o_phone, o_item_1, o_item_2, o_item_3, o_comments ) Values ( @firstname, @lastname, @address1, @address2, @city, @state, @zip, @email, @phone, @item1, @item2, @item3, @comments )GOSo it is working, just not completely and I am stumped here. Any help would be great! Thanks.
View 6 Replies
View Related