TableAdapter.Insert Method At VS .Net 2008.

Mar 28, 2008

Hi there,

i have a problem with my smart device application that i develop.

To simplify:

1) C# smart device appliccation
2)a database file *sdf
3)a typed dataset using the wizard to do so
4)TableAdapter with connection string with no problems(cool)
5)use of Insert method that returns 1 ( also cool) [--> MyTableAdapter.Insert("blabla","blablabla"); <------]
6)no saved records in the DB file(baaaaaad)

Plz any help would be appreciated.

Dimoklis
Software Developer

View 9 Replies


ADVERTISEMENT

How Do I Insert A Record With Possible NULL Values Using A Tableadapter.

Feb 26, 2008

I'm sorry, this question has a pretty long preamble, but bear with me as this will fully explain my problem, and save a number of clarification questions.I am using Visual Web Developer 2005 Express, with SQL Server 2005. After reading a Microsoft article saying that it was much better to use a three tier architecture with data adapters than to write explicit queries, I have used this approach extensively, and generally it works very well.  Typical code patterns are: -        Dim taPassenger As New ShippingTableAdapters.VPassengerTableAdapter        Dim tbpassenger As Shipping.VPassengerDataTable        Dim trpassenger As Shipping.VPassengerRow        .....        '   to process all passengers from a voyage: -        tbpassenger = taPassenger.GetDataByVOYid(Voyageid)        For Nbr As Integer = 1 To tbpassenger.Count            trpassenger = tbpassenger(Nbr - 1)             '    I now have the row available in properly-typed fields, eg trpassenger.vpxName             ...        Next        '   to read and process a single passenger        tbpassenger = tapassenger.GetDataByVPXid(VPXid)        trpassenger = tbpassenger(0)The table adapter has been created with Insert,Update, Delete methods.   Thus you can assign values to row fields, and then update the row: -        trpassenger.VPXName = "New Name"        ....        tapassenger.update(trpassenger)There are actually several overloads of the update method:  you could have written a field list, like this, where the names (VPXid etc) would be defined in my program as variables of the appropriate type for the corresponding column.        tapassenger.update(VPXid, VPXName, VPXAge, ....HOWEVER,  this doesn't work properly if you have non-string data that could be null.   Thus if the fourth field is a foreign key that could be null, if you write        Dim VPXVoyId as Nullable(of GUID)        VPXVoyid = nothing        tapassenger.update(VPXid, VPXname, VPXAge, VPXVoyid, ...or         Trpassenger.VPXVoyid = Nothing        tapassenger.update(trpassenger) you do NOT put a null value into the database.  Instead you store a value of "00000000-0000-0000-0000-000000000000".   You can solve this annoying problem in two ways: -A.   If you will ALWAYS be storing a null value at this point of your program, then simply write the update statement like this: -        tapassenger.update(VPXid, VPXname, VPXAge, Nothing, ...Here "Nothing" actually means "DBNull" even though it doesn't mean this when used in a normal VB assignment (and neither does DBNull).B   You can use the SetxxxxNULL method: -        If trpassenger.VPXVoyid = nothing then             trpassenger.SetVPXVoyidNull        End If        tapassenger.update(trpassenger) Thus when the program logic is complex and there are many paths to the update statement I will often put statements such as this in front of the update statement, using SetxxxxxNull for all non-string values that may be null.  You don't need to worry about string values because the Nullvalue property can be used to simply say that Null values are empty, and it all works properly, but for reasons unknown Microsoft have prohibited this for other data types. Now at last we get to my question, which is "How do I do the equivalent for an Insert?"   tapassenger.insert does not have any overloads, and the only form is  tapassenger.insert(field list).   But this creates the problem above:  if VPXVoyid = nothing then I insert the not-null value of "00000000-0000-0000-0000-000000000000".   If I COULD use the form tapassenger.insert(trpassenger), then I'd have another problem: if you haven't set trpassenger (for example with trpassenger = tbpassenger(0)) then it will not exist, so you will get an exception when you try to reference it.  Yet you can't write    If isnothing(trpassenger) then       trpassenger = new shipping.vpassengerrow)         (I've tries this both as an assignment, and as a Dim statement)    end ifSo far I can think of only two solutions, both awful: -a/    Use multi-choice logic to choose an appropriate insert statement.  If there is only one or two possibly-null fields, I could write:-        If field4 = nothing then            trpassenger.insert (VPXid, VPXname, VPXAge, Nothing, ..        However if there is more than one possibly-null field, you need (2 to the power of  nbr-of-possibly-null-fields) insert statements, with of course a lot of testing to choose which oneb/    I could insert the record with nulls, then read it back and update it.  Surely there is a better way!   Help! Thank you, Robert Barnes.    

View 2 Replies View Related

How To Call A Stored Procedure Just After A TableAdapter's INSERT Command Executes

Feb 29, 2008

All-
Is there a way that I can embedd a call to a stored procedure into an existing INSERT section in a table adapter?
Say my objective is to call a stored procedure called personfill automatically RIGHT AFTER the TableAdapter inserts a row into the person table. One catch is that the stored procedure must be sent the value of unique identifier field person_id, which was created for the new person record automatically by the db. (If this is not possible to do, I might try using a TRIGGER in the person table.)
Below is the INSERT code of the TableAdapter. My guess is that if I could call a procedure, I would want to put the call between lines 12 and 13.
Your comments would be most appreciated!!!
-Kurt1 <InsertCommand>
2 <DbCommand CommandType="Text" ModifiedByUser="false">
3 <CommandText>INSERT INTO [person] ([family_id], [circle_id], [person_type_id], [last], [first], [username], [password]) VALUES (@family_id, @circle_id, @person_type_id, @last, @first, @username, @password)</CommandText>
4 <Parameters>
5 <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Int16" Direction="Input" ParameterName="@family_id" Precision="0" ProviderType="SmallInt" Scale="0" Size="0" SourceColumn="family_id" SourceColumnNullMapping="false" SourceVersion="Current" />
6 <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Int16" Direction="Input" ParameterName="@circle_id" Precision="0" ProviderType="SmallInt" Scale="0" Size="0" SourceColumn="circle_id" SourceColumnNullMapping="false" SourceVersion="Current" />
7 <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="Int16" Direction="Input" ParameterName="@person_type_id" Precision="0" ProviderType="SmallInt" Scale="0" Size="0" SourceColumn="person_type_id" SourceColumnNullMapping="false" SourceVersion="Current" />
8 <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@last" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="last" SourceColumnNullMapping="false" SourceVersion="Current" />
9 <Parameter AllowDbNull="false" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@first" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="first" SourceColumnNullMapping="false" SourceVersion="Current" />
10 <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@username" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="username" SourceColumnNullMapping="false" SourceVersion="Current" />
11 <Parameter AllowDbNull="true" AutogeneratedName="" DataSourceName="" DbType="AnsiString" Direction="Input" ParameterName="@password" Precision="0" ProviderType="VarChar" Scale="0" Size="0" SourceColumn="password" SourceColumnNullMapping="false" SourceVersion="Current" />
12 </Parameters>
13 </DbCommand>
14 </InsertCommand>
15 <SelectCommand>
16 <DbCommand CommandType="Text" ModifiedByUser="true">
17
 

View 2 Replies View Related

Simplest Method For SQL Insert

Jun 13, 2007

I have spent the afternoon researching this, and to no avail so here's my question.
I have a user input form with upwards of 60 fields that are to be filled in by the user (intranet environment).  I want to post those values as a new record in an SQL database.   I have setup an SQLDataAdapter tied to a parameterized stored procedure on the SQL server.   I can successfully post data from the controls on the form when I set the parameter type to Control based.
Here's the problem, though.  I need to do some pre-processing on most of the values in the controls on the form.  I have setup VB code (that executes when the user clicks the "Submit" button), that pulls in each control value, performs any necessary processing, and sets a variable to the value I actually want stored in the DB.  How can I assign THAT value (from the variable) to the parameter for the stored procedure?  
Thanks,
Dave

View 5 Replies View Related

Question Of Insert Method,need Help!!

Feb 28, 2007

Hi,
i am using vs2005 and microsoft SQL server mobile edition (.NET Framework Data Provider for SQL Server CE) to develop an application for wm5.0 pocket pc in language C# and now, i'm facing a problem on how to insert a new data into .sdf file with TableAdapter?example, i have a combo box and a button (known as AddButton) on my form1.cs, when i click the button, all the data from combo box will automatic insert into a database. How to write the codes for this? i tried for a few methods to wrote it and it seems do not work.Does anybody know how to write it?Thank you.

View 3 Replies View Related

DataSet And Insert Method

Apr 6, 2006

hi,

i created a query to insert a row in DataSet in Visual Studio 2005. i gave the method name to the query i created. as i understood it returns '1' if successful or '0' if not.

is it possible to get the ID or the row instead?

View 7 Replies View Related

Why Isnt My Insert Method Working

Feb 18, 2008

hi, i am trying to insert my values into the database, however the code i have doesnt seem to work. i have looked at old posts, one suggested to take away my code behind code where the insert method has been written. i did try this but it does not seem to work, can some please help me sort out this problem and advice or examples of what i need to do will be very much appreciated, thank you. the following is the code i have
code behind code
'Save vlues into database.
If IsPostBack = False ThenDim test As SqlDataSource = New SqlDataSource()
test.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ToString()
test.InsertCommand = "INSERT INTO [UserQuiz] ([QuizID], [DateTimeComplete], [CorrectAnswerCount], [UserName]) VALUES (@QuizID, @DateTimeComplete, @CorrectAnswerCount, @UserName)"test.InsertParameters.Add("QuizID", Session("QuizID").ToString())
test.InsertParameters.Add("DateTimeComplete", DateTime.Now.ToString())test.InsertParameters.Add("CorrectAnswerCount", "12")test.InsertParameters.Add("UserName", User.Identity.Name)
test.Insert()
End If
 
when i run the program i get this error
Cannot insert the value NULL into column 'UserQuizID', table 'C:VISUAL STUDIO 2008WEBSITESquizAPP_DATAQUIZ.MDF.dbo.UserQuiz'; column does not allow nulls. INSERT fails.The statement has been terminated.
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: Cannot insert the value NULL into column 'UserQuizID', table 'C:VISUAL STUDIO 2008WEBSITESquizAPP_DATAQUIZ.MDF.dbo.UserQuiz'; column does not allow nulls. INSERT fails.The statement has been terminated.Source Error:



Line 26: test.InsertParameters.Add("UserName", User.Identity.Name)
Line 27:
Line 28: test.Insert()
Line 29:
Line 30: End If

View 4 Replies View Related

What Does 'No Overload For Method 'Insert' Takes '1' Arguments' Mean?

Dec 10, 2007

code that caused this error: line AddInBookSqlDataSource2.Insert(item);protected void inbookButton_Click(object sender, EventArgs e){
try{
AddInBookSqlDataSource1.Insert();
}catch (Exception ex){
uploadSPoneLabel.Text = "Saved Failed: SP One" + ex.Message;
}foreach (ListItem item in authorsListBox5.Items){
try{
AddInBookSqlDataSource2.Insert(item);
saveStatusLabel.Text = "Save Successful: SP Two";
}catch (Exception ex1){saveStatusLabel.Text = "Save Failed: SP Two" + ex1.Message;
}
}
}
any help appreciated
Thanks in advance

View 1 Replies View Related

Method To Insert All Record From Access Table To SQL Server One

Jul 20, 2005

Anyone know if there is method that can insert all record from a tablein an MS Access 2000 database to a table in MS SQL Server 2000database by a SQL statement? (Therefore, I can execute the statementin my program)--Posted via http://dbforums.com

View 3 Replies View Related

Using An Optimised Method To Insert A Variant Type Array To DB

Feb 13, 2008

Hi, I was wondering if there is a method (other than BULK INSERT) to insert a (C++) application level array into the database, I have a variant type array populated with values that I want to insert, perhaps using ADO objects in quick time!

View 1 Replies View Related

Inserting TextBox Values To Database Using SqlDataSource.Insert Method

Oct 25, 2006

Hi, it is few days I posted here my question, but received no answer. Maybe the problem is just my problem, maybe I put my question some strange way. OK, I try to put it again, more simply. I have few textboxes, their values I need to transport to database. I set SqlDataSource, parameters... and used SqlDataSource.Insert() method. I got NULL values in the database's record. So I tried find problem by using Microsoft's sample code from address http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insert.aspx. After some changes I tried that code and everything went well, data were put into database. Next step was to separate code beside and structure of page to two separate files followed by new test. Good again, data were delivered to database. Next step: to use MasterPage, very simple, just with one ContentPlaceHolder. After this step the program stoped to deliver data to database and delivers only NULLs to new record. It is exactly the same problem which I have found in my application. The functionless code is here:http://forums.asp.net/thread/1437716.aspx I cannot find any answer this problem on forums worldwide. I cannot believe it is only my problem. I compared html code of two generated pages - with maserPage and without. There are differentions in code in ids' of input fields generated by NET.Framework:Without masterpage:<input name="NazevBox" type="text" id="NazevBox" /><span id="RequiredFieldValidator1" style='color:Red;visibility:hidden;'>Please enter a company name.</span><p><input name="CodeBox" type="text" id="CodeBox" /><span id="RequiredFieldValidator2" style='color:Red;visibility:hidden;'>Please enter a phone number.</span><p><input type="submit" name="Button1" value="Insert New Shipper" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;Button1&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="Button1" /> With masterpage:<input name="ctl00$Obsah$NazevBox" type="text" id="ctl00_Obsah_NazevBox" /><span id="ctl00_Obsah_RequiredFieldValidator1" style='color:Red;visibility:hidden;'>Please enter a company name.</span><p><input name="ctl00$Obsah$CodeBox" type="text" id="ctl00_Obsah_CodeBox" /><span id="ctl00_Obsah_RequiredFieldValidator2" style='color:Red;visibility:hidden;'>Please enter a phone number.</span><p><input type="submit" name="ctl00$Obsah$Button1" value="Insert New Shipper" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$Obsah$Button1&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="ctl00_Obsah_Button1" />In second case ids' of input fields have different names, but I hope it is inner business of NET.Framework.There must be something I haven't noticed, maybe NET's bug, maybe my own. Thanks for any suggestion.

View 2 Replies View Related

Transact SQL :: Method To Generate Insert Statements For Data In A Table

May 30, 2013

I have a database which will be generated via script. However there are some tables with default data that need to exist on the database.I was wondering if there could be a program that could generate inserts statments for the data in a table.I know about the import / export program that comes with SQL but it doesnt have an interface that lets you copy the insert script and values into an SQL file (or does it?)

View 7 Replies View Related

SQL Server 2012 :: Set Based Method To Insert Missing Records Into Table - Right Join Not Work

Apr 24, 2014

I have table A (EmployeeNumber, Grouping, Stages)
and
Table B (Grouping, Stages)

Table A could look like the following where the multiple employees could have multiple types and multiple stages.

EmployeeNumber, Type, Stages
100, 1, Stage1
100, 1, Stage2
100, 2, Stage1
100, 2, Stage2
200, 1, Stage1
200, 2, Stage2

Table B is a list of requirements that each employee must have. So every employee must have a type 1 and 2 and the associated stages listed below.

Type, Stage
1, Stage1
1, Stage2
2, Stage1
2, Stage2
2, Stage3
2, Stage4

So I know that each employee should have 2 Type 1's and 4 Type 2's. I hope that makes sense, I'm trying to change my data because ours is very proprietary.

I need to identify employees who do not have all their stages and list the stages they are missing. The final report should only have employees and the associated missing types and stages.

I do a count by employee to see how many types they have to identify the ones that don't have all the types and stages.

My count would look something like this:

EmployeeNumber Type Total
100, 1, 2
100, 2, 2
200, 1, 1
200 1, 2

So I know that employee 100 should have 2 more Type 2's and employee 200 should have 1 more Type 1 and 2 more Type 2's based on the required list.

The problem I'm having is taking that required list and joining to my list of employees with missing data and pulling from it the types and stages that are missing by employee. I thought I could get a list of the employees that are missing information and right join it to the required list where the missing records would be nulls. But, that doesn't work because some employees do have the required information and so I'm not getting any nulls returned.

View 9 Replies View Related

Send Request To Stored Procedure From A Method And Receive The Resposne Back To The Method

May 10, 2007

Hi,I am trying to write a method which needs to call a stored procedure and then needs to get the response of the stored procedure back to the variable i declared in the method. private string GetFromCode(string strWebVersionFromCode, string strWebVersionString)    {      //call stored procedure  } strWebVersionFromCode = GetFromCode(strFromCode, "web_version"); // is the var which will store the response.how should I do this?Please assist.  

View 3 Replies View Related

SQL Server 2008 :: Insert Data Into Table Variable But Need To Insert 1 Or 2 Rows Depending On Data

Feb 26, 2015

I am writing a query to return some production data. Basically i need to insert either 1 or 2 rows into a Table variable based on a decision as to does the production part make 1 or 2 items ( The Raw data does not allow for this it comes from a look up in my database)

I can retrieve all the source data i need easily but when i come to insert it into the table variable i need to insert 1 record if its a single part or 2 records if its a twin part. I know could use a cursor but im sure there has to be an easier way !

Below is the code i have at the moment

declare @startdate as datetime
declare @enddate as datetime
declare @Line as Integer
DECLARE @count INT

set @startdate = '2015-01-01'
set @enddate = '2015-01-31'

[Code] .....

View 1 Replies View Related

Update Method Is Not Finding A Nongeneric Method!!! Please Help

Jan 29, 2008

Hi,
 I just have a Dataset with my tables and thats it
 I have a grid view with several datas on it
no problem to get the data or insert but as soon as I try to delete or update some records the local machine through the same error
Unable to find nongeneric method...
I've try to create an Update query into my table adapters but still not working with this one
Also, try to remove the original_{0} and got the same error...
 Please help if anyone has a solution
 
Thanks

View 7 Replies View Related

SQL Login With TableAdapter

Jul 31, 2006

Ok, just made a TableAdapter and the SELECT statement works fine and pulls data. But doing an INSERT is something different, it craps out wanting a login.
No neat Wizard (or so I haven't found yet) that lets me give the TableAdapter the login info for the SQL Server, which I have. 
Do I need to write code with the login and password for the SQL connection instead?
-Ed

View 1 Replies View Related

Problem With T-SQL In TableAdapter

Jul 11, 2007

Hi,
I have a TableAdapter created in a Dataset. I'm creating a search function for a table, and here's how my code looks like in the "Add Query" wizard:
Select * from Event where eventname like '%@EventName%'
But when I click on preview data, I do not get the prompt to enter a value for the @EventName parameter, where went wrong?

View 4 Replies View Related

I/O Blob Through TableAdapter

May 26, 2006

What's a good way to work with Blobs and TableAdapters, in terms of declaring compatible column types in SQL Server and DataTable fields?

View 2 Replies View Related

TransactionScope And TableAdapter

Jul 30, 2007

This thread has also been posted under '.NET Data Access and Storage'. However, I have realized that the same code contruction using SQL Server connection- and tableadapter objects work fine so I am trying to get answers here also.

I am attempting to do transactional updates to SQL Compact Edition database using TableAdapter and TransactionScope like this:


using (TransactionScope ts = new TransactionScope())

{


SqlCeConnection sqlConn = new SqlCeConnection(connectionString);

myTableTableAdapter ta = new myTableTableAdapter();

ta.Connection = sqlConn;

ta.Update(dsmyTable.myTable);
ts.Complete();

}


dsmyTable is a strongly typed dataset created through the Dataset Designer and populated with data from the database prior to the code sample above.

This all works fine. However, when removing the call to 'ts.Complete()' to simulate the transaction rolling back, data is still stored into the database.

Am I missing something here or does TransactionScope not support SQL Compact Edition? Any help is appreciated!

Regards.

View 3 Replies View Related

TableAdapter And Variable

Sep 5, 2006

Hello,



I want to do something like this in a TableAdapter's SQL Statement:



SELECT Type.*

FROM Controllers INNER JOIN

@Type AS Type ON Type.ConfigurationId = Controllers.ActiveConfig INNER JOIN

Tank ON Controllers.ControllerId = Tank.ControllerId

WHERE (Tank.TankId = @TankId)



But I get an error because of the @Type variable. Is there any other way to choose a table in a TableAdapter with variables?



Thanks for your help!

View 3 Replies View Related

SQL Server 2008 :: Cannot Insert Duplicate Key Row In Object

Jun 6, 2011

I have a SQL Server 2008 R2 on a windows 2008 server.After one failed backup, I started getting these errors:

Error: 2601, Severity: 14, State: 1.Cannot insert duplicate key row in object 'sys.syscommittab' with unique index 'si_xdes_id'.

Error: 3999, Severity: 17, State: 1.Failed to flush the commit table to disk in dbid 5 due to error 2601. Check the errorlog for more information.

From Microsoft, I found this:

A backup Operation On A SQL Server 2008 Database Fails If You Enable Change Tracking On This Database

[URL]

But this bug refers to SQL Server 2008. What should I do if in my case is a R2 version?

View 5 Replies View Related

SQL Server 2008 :: Identity Column Insert

Apr 28, 2015

I have two tables having one row identifier column each of int datatype. Both these columns are part of the respective primary keys. Now as a part of my process, i'm inserting one small part of data from one table to another table. This was working fine but suddenly started getting error like

Violation of PRIMARY KEY constraint 'PK_TargetTable'. Cannot insert duplicate key in object 'DW.TargetTable'. The duplicate key value is (58544748).First I checked with DBCC CHECKIDENT with NORESEED and found that there is difference in the current identity value and current column value. I fixed it by running DBCC CHECKIDENT. But to my surprise again got the same issue. interesting thing is that the error comes after inserting 65466 records.

View 4 Replies View Related

SQL Server 2008 :: Insert The File In Other Database?

May 21, 2015

I work with sql server 2008 on a database.we have export schema and datas with the command export datas

click rigth on database => tasks => generate scripts => select all object => click advanced => select type of data to script => schema and data

Now we have a file with all datas and schema That's perfect ...But how i can insert the file in a other database?ok i can copy paste all datas in management studio and press f5 but when i do this the management studio fail because the size of the file is > 200 mega !

View 3 Replies View Related

SQL Server 2008 :: INSERT INTO Not Inserting Enough Rows

May 22, 2015

I've got a piece of code that returns 53 records when using just the SELECT section.When I change it to INSERT INTO ..... SELECT it only inserts 39 records into the receiving table.There are no keys/contraints/indices or anything else on the receiving table (it's just a dumping ground for some data that will be processed later).

The code for creating the table is here:-
USE [CDSExtractInpatients6.2]
GO
/****** Object: Table [dbo].[CDS_Inpatients_CDS_Feeds_Import] Script Date: 22/05/2015 15:54:15 ******/
SET ANSI_NULLS ON
GO

[code]...

I know most of the date fields are being created as varchar on here, but this is something I inherited and the SELECT is outputting the dates as text.Don't know if it makes any difference, but the server is running SQL2008.

View 9 Replies View Related

SQL Server 2008 :: Deadlocks With INSERT Statement

Sep 28, 2015

Have any seen Insert statement deadlocking itself ? Most of the articles published by Microsoft says to change the transaction isolation level from Read Committed to Read Committed Snapshot.Below is the XML file on the deadlock

<deadlock>
<victim-list>
<victimProcess id="processe259948" />
</victim-list>
<process-list>

[code]...

View 0 Replies View Related

SQL Server 2008 :: Loop To Insert 0s Into Table

Oct 22, 2015

I have a problem where I want to create a loop in my script to insert 0's into my table.

I have a temp table with a list of company codes.

SELECT CODE FROM ##SENData GROUP BY CODE

This produces the following;

CODE
00C
00D
00K
00M
00Q
00T
00V
00X (there are 110 of these codes)

I want to insert data into a different table in the following format.

+------+------------+-------+---------+
| CODE | Month | Value | Measure |
+------+------------+-------+---------+
| 00C | 01/09/2015 | 0 | HAR-01 |
| 00D | 01/09/2015 | 0 | HAR-01 |
| 00K | 01/09/2015 | 0 | HAR-01 |
| 00M | 01/09/2015 | 0 | HAR-01 |
| 00Q | 01/09/2015 | 0 | HAR-01 |
| 00T | 01/09/2015 | 0 | HAR-01 |
| 00V | 01/09/2015 | 0 | HAR-01 |
| 00X | 01/09/2015 | 0 | HAR-01 |
+------+------------+-------+---------+

The month will be set from a declared variable and the others will just be hard coded.

View 3 Replies View Related

Passing Parameters In TableAdapter

Jul 28, 2006

A little new to ASP.NET pages, and I'm trying to pass some parameters to a SQL 2000 Server using a TableAdapter, code is as follows:
------
TestTableAdapters.test_ModemsTableAdapter modemsAdapter = new TestTableAdapters.test_ModemsTableAdapter();
// Add a new modem
modemsAdapter.InsertModem(frmRDate, frmModem_ID, frmProvisioning, strDecESN );
--------
And the error I get when loading the ASP.NET page is as follows:
Compiler Error Message: CS1502: The best overloaded method match for 'TestTableAdapters.test_ModemsTableAdapter.InsertModem(System.DateTime?, string, string, string)' has some invalid arguments
---------------
Now I realized the four strings that I am trying to pass to the server refer to ID's on Textboxes on the web page. Not sure if that might be the problem for databinding... ? Or is it my statement for the adapter?
-Ed

View 4 Replies View Related

TableAdapter Class Not Generated

Aug 2, 2006

I created a new DataSet object using the
wizard and had no probs, it's very straightforward.  I created a
GetProducts() method and also added a GetProductCount() method.  I
read somewhere that when the DataSet is saved, it will generate the
TableAdapter classes and store them in the project nested under the
DataSet object.  This isn't happening, the files aren't there and
yes I'm displaying all files.  There *is* however the TableAdapter
class but it's in not in the project, it's a temporary file w/ the
following path:
   
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Temporary ASP.NET
Fileswebsitef38f8b5500014aeSources_App_Codepw_products.xsd.72cecc2a.cs.

I saved the DataSet several times, compiled the entire solution and
even closed the solution yet this temporary file isn't getting saved
where it should be.  Does anyone have any ideas abt this? 
I'm eager to start developing my DAL and def want to use these
TableAdapter classes.

Thx in advance,
-Pete

View 2 Replies View Related

Tableadapter Query Question

Nov 20, 2006

hii am using the nothwind database for a current exercise, i am wanting to user to be able to search for products based on two input methods (product name, category).here is the code i currently have: SELECT    DISTINCT  ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued, ProductName,                       ProductID, CategoryIDFROM         ProductsWHERE       (CategoryID = @categoryID) OR                       (ProductName LIKE '%' + @ProductName + '%')i'm wanting to have it set so the user can use both input methods, or either, when one input method is used by the user it works fine, but when both are used it generates results for 2 seporate queriesi'm wanting to have it set so the user can search by product name in certain categories (when both search input methods are used)how would i go about doing this? is there some kind of equivalent to an AND/OR statement?eg.  WHERE       (CategoryID = @categoryID) AND OR
                      (ProductName LIKE '%' + @ProductName + '%') thanks in advance! 

View 2 Replies View Related

Going From Sqlconnection And Sqlreader To Using A Tableadapter And ????????

Apr 13, 2007

Below is my code right now Im using a direct sqlconnection for each request. I would like to use Tableadapters and/or my BLL code like the rest of my sites pages. I cant find how to do this progamatically and using the xmltextwriter. (Also i need to be able to name the xml output nodes like below)Thanks for the help.NeilPrivate Sub GetAllEvents(ByVal SqlString)    Response.Clear()    Response.ContentType = "text/xml"    Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)    objX.WriteStartDocument()    objX.WriteStartElement("Events")    Dim objConnection As New SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|*********.mdf;Integrated Security=True;User Instance=True")    objConnection.Open()    Dim sql As String = SqlString    Dim objCommand As New SqlCommand(sql, objConnection)    Dim objReader As SqlDataReader = objCommand.ExecuteReader()    While objReader.Read()      objX.WriteStartElement("Event")      objX.WriteAttributeString("EventId", objReader.GetInt32(0))      objX.WriteAttributeString("EventName", objReader.GetString(1))      objX.WriteAttributeString("EventDescription", objReader.GetString(2))      objX.WriteAttributeString("EventDate", objReader.GetDateTime(3))      objX.WriteAttributeString("CurrentDate", Date.Now.ToString)      If Not objReader.IsDBNull(12) Then        objX.WriteAttributeString("EventImage", objReader.GetString(12))      End If      objX.WriteEndElement()    End While    objReader.Close()    objConnection.Close()    objX.WriteEndElement()    objX.WriteEndDocument()    objX.Flush()    objX.Close()    Response.End()  End Sub

View 2 Replies View Related

If/then Parameterized Queries Using Tableadapter

Jun 29, 2007

Hey fellas.  Here's my situation.  I have two textboxes where the user enters a "start" date and an "end" date.  I want to search a table to find records who's "expired" column date is between those two dates provided by the user.  The tricky part is, if the user just puts a start date in but no end date, I want it to search from whatever start date the user entered to the future and beyond.  Essentially, I think I'm looking for a SQL statement along the lines of:
  SELECT Request.RequestID, Request.URL, ActionProvider.Name, Request.CurrentStageID, Request.Decision, Request.SubmissionDate,
Request.ExpirationDate
FROM Request INNER JOIN
RequestSpecificActionProvider ON Request.RequestID = RequestSpecificActionProvider.RequestID INNER JOIN
ActionProvider ON RequestSpecificActionProvider.ActionProviderID = ActionProvider.ActionProviderID INNER JOIN
RoleActionProvider ON ActionProvider.ActionProviderID = RoleActionProvider.ActionProviderID INNER JOIN
Role ON RoleActionProvider.RoleID = Role.RoleID
WHERE

CASE WHEN @BeginDate is not null AND @BeginDate <> ''
THEN Request.ExpirationDate > @BeginDate
END

AND

CASE WHEN @EndDate is not null AND @EndDate <> ''
THEN Request.ExpirationDate > @EndDate
END

AND (Role.Description = 'Requestor')

 
I realize my code isn't correct and there's still a floating "AND" out there I would have to put some logic around.  Anyway, how do I do this?  Do I need to build three separate queries in my tableadapter (one for if both dates are provided, one for if start date is provided, one for if end date is provided) and build the logic in my application code or can I tackle it with SQL?  If I can tackle it with SQL, where have I gone astray?  I'm currently getting the error: "Error in WHERE clause near '>'. Unable to parse query text."
 Thanks for the help everyone!

View 3 Replies View Related

TableAdapter And Connection Strings

Sep 19, 2007

Hello,
I'm trying to setup a typed dataset with a table adapter in .NET 2.0, and the problem I am having is that I cannot get the table adapter to use existing connection strings setup in the web.config file.  How can I get it to do so?  It doesn't see the connection strings, and so it wants me to create a new connection, which I don't want to do.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved