How Can I Capture The Id Columne From A New Datarow?

May 14, 2007

In my BLL I have a method that adds a new row to a table in the database...

[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
    public bool AddContact(string firstname, string lastname, string middleinit, bool active, Guid uid, bool newsletter)
    {
        ContactsDAL.tblContactsDataTable contacts = new ContactsDAL.tblContactsDataTable();
        ContactsDAL.tblContactsRow contact = contacts.NewtblContactsRow();

        contact.FirstName = firstname;
        contact.LastName = lastname;
        contact.MiddleName = middleinit;
        contact.Active = active;
        contact.UserID = uid;
        contact.Newletter = newsletter;

        contacts.AddtblContactsRow(contact);
        int rowsAffected = Adapter.Update(contact);

        return rowsAffected == 1;
    }

The primary key in this table is a BigInt set as an identity column....How do I capture the value of the primary key that gets created when the new row is added?

View 3 Replies


ADVERTISEMENT

DataRow Syntax

Feb 7, 2007

command.CommandText = “SELECT UserName from Users WHERE UserID =  “ = userID
 
Executing this command returns one table with one column with one row.  What is the syntax for getting that value into a variable?  I can get the information into a dataSet but I can’t get it out.  Should I be using a dataSet for this operation?
 
The rest of the code so far:
 
SqlDataAdapter dataAdapter = new SqlDataAdapter();
            dataAdapter.SelectCommand = command;
            dataAdapter.TableMappings.Add("Table", "Users");
 
            dataSet = new DataSet();
            dataAdapter.Fill(dataSet);

View 3 Replies View Related

DataRow Array

Jan 16, 2008

Hi,
 i m pretty new to this forum and c#.net 
i m doin a project in c#.net
I have four values in my datarow array
for example
DataRow[] cmb;
cmb=dsResult.Tables[0].Select("Controls Like 'cmb%'");// Here i m getting four Rows
 
for(i=0;i<cmb.Length;i++)
{
cmb[i]=Session["cmb'+i].ToString().Trim()//Here i m getting error;Cannot implicitly convert type 'string' to 'System.Data.DataRow'
}
 
 How to assign my session values to them.
I want to assign my value stored in the session variable to that array.Is there any way i can do it.Can i convert datarow array to string array! Please can any one help
me.
 

View 6 Replies View Related

Problem Returning A Datarow

Jul 23, 2005

Hi,I have a client/server app. that uses a windows service for the server and asp.net web pages for the client side. My server class has 3 methods that Fill, Add a new record and Update a record. The Fill and Add routines work as expected but unfortunately the update request falls at the 1st hurdle.I pass two params to the remote(server) method for the update, one is the unique ID and the other is a string that is the name of the table in the database. See code below. I need the SelectedRow method to return a datarow that will then populate textbox's on another page. When the method is called I get an 'internal system error.....please turn on custom errors in the web.config file on the server for more info.(unfortunately my server is not s web server so I don't have a web.config file!!).Can anyone see anything obvious.Cheers. >>Calling routine:Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadSystem.Threading.Thread.CurrentThread.CurrentCultu re = New CultureInfo("en-GB")hsc = CType(Activator.GetObject(GetType(IHelpSC), _"tcp://192.168.2.3:1234/HelpSC"), IHelpSC)Dim drEdit As DataRowDim intRow As Integer = CInt(Request.QueryString("item"))strDiscipline = Request.QueryString("discipline")drEdit = hsc.SelectedRow(intRow, strDiscipline) <<Call the remote methodstrRecord = drEdit.Item(0)txtLogged.Text = drEdit(1)txtEngineer.Text = drEdit.Item(3)End SubRemote Class Function:Public Function SelectedRow(ByVal id As Integer, ByVal discipline As String) As System.Data.DataRow Implements IHelpSC.SelectedRowstrDiscipline = Trim(discipline)Dim cmdSelect As SqlCommand = sqlcnn.CreateCommandDim drResult As DataRowDim strQuery As String = "SELECT * FROM " & strDiscipline & _" WHERE CallID=" & idcmdSelect.CommandType = CommandType.TextcmdSelect.CommandText = strQuerysqlda = New SqlDataAdaptersqlda.SelectCommand = cmdSelectds = New DataSetsqlda.Fill(ds, "Results")drResult = ds.Tables(0).Rows(0)Return drResultEnd Function

View 3 Replies View Related

Case Senitive SQL Quary Using Datarow

Mar 14, 2008

I have in SQL Table1 the following values in Field1:

ABC
ABc
AbC
abc
aBc
abC  Select Field1 From Table1 Where Field1 = "AbC"

I get all six records, not just the one record (AbC) that I want to retrieve. How do I tell the select statement to be case sensitive?
 my asp.net statement is given below  DataRow dr1 = ds.Tables["Login"].Select("UserId ='" + txtUserId.Text + "'And Passwords ='" + txtPassword.Text + "'")[0]; i m using datarowso i need a helpi have quary but i don;t know how can use  DataRow dr1 = ds.Tables["Login"].Select("UserId ='" + txtUserId.Text + "'And Passwords ='" + txtPassword.Text + "'where CONVERT(binary(5),Userid)=CONVERT(binary(5),'" + txtUserId.Text + "')'" )[0];                                      this give me error "Where condiction need operator"waiting for reply 

View 2 Replies View Related

Simple DataRow Navigation Question

Sep 7, 2005

Hi. I am new to ADO.NET and I can't seem to figure out how to populate a row that is a layer lower than the instantiated row. I am populating and XML file called Users.xml:


Code:


<user>
<registerDate>9/6/2005</registerDate>
<firstName>TempUser</firstName>
<lastName>TempUser</lastName>
<emailAddress>TempUser</emailAddress>
<password>5F4DCC3B5AA765D61D8327DEB882CF99</password>
<securityQuestion>TempUser</securityQuestion>
<securityAnswer>TempUser</securityAnswer>
<zipCode>TempUser</zipCode>
<uniqueID>TempUser</uniqueID>
<alternateEmail>TempUser</alternateEmail>
<gender>TempUser</gender>
<industry>TempUser</industry>
<occupation>TempUser</occupation>
<jobtitle>TempUser</jobtitle>
<maritalstatus>TempUser</maritalstatus>
<birthDay>
<month>TempUser</month>
<day>TempUser</day>
<year>TempUser</year>
</birthDay>
<homelocation>...



and, i am using the below code to access and populate the rows based on the users registration input:


Code:


Dim NewLogin As Data.DataRow = LoginDS.Tables(0).NewRow



I am able to access all the rows that are one layer into the xml file with the following code:


Code:


NewLogin("someNode") = _someNode.Text



but, how do i populate nodes that are "further down" such as "birthDay". Do i have to reinstantiate NewLogin as ...Tables(1).NewRow? I have tried various forms of this and it doesnt work. Suggestions appreciated... thanks.

View 1 Replies View Related

Can We Specify Datarow Locking In Create Table Statement

Sep 24, 2007

Hi guys,

I have a question regarding a locking scheme in MSSQL I hope you guys can help. In Sybase, I am able to specify datarow locking in DDL (ex. create table, alter table). Can I do the same in MSSQL or is there an equivalent option in CREATE TABLE statement in MSSQL? I came across a few articles in MSDN about datarow locking and it seems to me that MSSQL only allows locking through DML... Is that true? Thanks.

View 2 Replies View Related

Primary Key In Datarow After Update Works In Access Not In Sql Server

Feb 15, 2005

Heys

a while back i had to do a project with an access database, one of the biggest problems i had back then was gettting the primary key
of a datarow you had just inserted into the database.

After a long set of trial and error i came up with the following:

- add the tablemappings of a table
- call the dataadapte.fillschema method

then after inserting a new row into the database the primary key gets filled in automatically!

now thing is

i was hoping to duplicate this in sql server

but it doesn't seem to work at all

so after i insert a row into my datatable
and update it
the row is in the database
but in vb the datarow primary key is not filled in!
anyone have an idea?

prefereabely one that does not resort to stored procedures with return parameters etc

thx a million in advance!

View 1 Replies View Related

ForEach Container With ADO Enumerator - Accessing The Current DataRow?

May 2, 2008

I will attempt to explain my situation more clearly.

I need to get data from a data source using a DataFlow Task (which pushes the DataSet into a Variable) and process the data row by row in a ForNext (ADO Enumerated) Container. I don't want to map the columns into variables because the number of columns and the data types vary considerably and I want to make my package as "generic" as possible.

Is there a way, in Script, to read the current row of the ForEach Container from into an ADO DataRow so that thie names and values of each column can be accessed?

I know how to read the entire DataSet object from a Variable into an ADO DataSet and iterate through the rows in the normal way but this doesn't suit my purpose. It would be really useful if there was a way to do somehing similar with the current DataRow in the ForEach Container.

To explain what I am doing, the idea is to use the Column Names and Values for each row to construct an xml fragement, store it in a string Variable and (in the next step) use the Web Services Task to call a Web Method with the xml fragment (from the Variable) as one of the inputs.

A less attarctive alernative would be to use a Scipt outside a ForEach Container and loop through the rows of teh DataTable as descibed above and perhaps call the Web Service Task from teh Script. The proble is that I don't know how to do this either and it woudl be much "neater" anyway to use the ForEach Container.

Any ideas?

View 7 Replies View Related

Capture Changes

May 23, 2002

Is there a way to capture every change made in a database? I would like to be able to audit and report on all changes made in our corp. database. Is there a system tool or function that can accomodate such a thing? Transaction Log maybe??

View 3 Replies View Related

How To Capture Before And After Changes Of DDL

Aug 3, 2015

I have to create DDL trigger for audit to capture the object definition before and after the changes.

Like If any user running the Alter table Statement, i need to capture the Object definition before and after changes..

View 3 Replies View Related

Event Capture

Jul 27, 1998

Hi,
We would like to capture events in our system. There seem to be
three obvious capture points for us - application, triggers, transaction
log. The latter seems to be the most attractive, since we`re looking
for a solution with minimal performance impact. In general, our
problem is similar to populating data warehouses from on-line databases.
Can anyone proffer some advice? In particular, being quite new to
SQL Server, I am not sure how difficult/possible it is to read the
transaction log in order to cull events. Some direction here would
be greatly appreciated.
Thanks,
Karl

View 1 Replies View Related

Capture Error

May 2, 2002

Hi all,
Is there anyway to capture the SQL Server Error and act accordingly?
I donot want sql server to raise an error when a Primary key violation has occured. Instead i want to capture that error(number,description etc) and act
accordingly.
Whats happening is, from the application we are trapping this sql error
and raising it. Instead, if somebody inserts a record which already exists, then we want to trap that error from the sqlprocedure itself and then do an update to that record.

thanks for the help

View 1 Replies View Related

Capture A Sql Command

Aug 16, 2006

Hi All.

I have this project that I need help with. There are 9 tables that I need to capture everything that happens to them (update, insert, delete). I was thinking of creating triggers. If someone does any of these actions against them then I need to insert into another table the date, the table name, the command that was run, and the records that are affected by it. Now I know how to do the date and table name, that's easy. My question is how do I capture the command. Once I have the command I can get the records affected.

If anyone knows how to do this, please help.

Thanks,
ODaniels

View 5 Replies View Related

Text Capture

Jan 30, 2004

I was wondering how you go about capturing text as it is entere into a textarea? i want it captured exactly as it is typed, with carriage returns and everything. is there an easy way to do this?

View 14 Replies View Related

Capture NT User ID

Apr 5, 2007

Access front-end, SQL Server 2005 backend.I have users connected to SQL Server via a Microsoft Access user-interface.Connection is via NT login.I want to log users' activities to the database with their userid.How can I capture their NT User ID (via VBA in Access)?Thanks,Bubbles

View 1 Replies View Related

Capture I/O Per Database

Mar 29, 2007

Hi,



Please help me how can i capture I/O operation per database SQLServer2005.



Regards

Sufian

View 5 Replies View Related

How To Capture Old And New Value In Trigger

Dec 18, 2007



Hi,

in sql server 2005, i was using update trigger with BEFORE but it gives error that
"'BEFORE' is not a recognized trigger."

My requirement is that i want to capture the old value as well as new value of
a column of the updated row in a trigger.

How can i perform this.

thanks in advance

View 3 Replies View Related

CAPTURE DML FROM TRIGGER

Jun 12, 2006

Hi All!

 SQL Server 2000

I've situation where I've to capture a DML executing against let say Table1 and later may at the end of the day or week I want to be able to extract all the DML executed against Table1 and execute them against similar tables on different sql server to synchronize the data. I don't want to use profiler as this is quite expensive resource for my problem niether can use any third party tool.

 

Is it possible to capture sql statement in the trigger?

 

I hope I made my question clear. Urgent help will be highly appreciated.

 

--Sohail.

View 3 Replies View Related

Capture Delta

Oct 13, 2006

how can I capture delta in SQL Server 2005 to refresh base tables in a data warehouse?

View 8 Replies View Related

How To Capture The Correct Identity Value

Sep 15, 2006

I have a stored procedure which will do 2 insert statements on 2 different tables. In my 2nd insert statement, I need to know how to capture the exact identity primary key value of the newly inserted record from the first insert statement. I am not sure how to get the correct key value of the new record because there may be more than one user inserting at the same time. Therefore, it is tough to capture the key value that belongs to the user doing his transaction at the time. Please help out. Thanks in advance.blumonde

View 6 Replies View Related

How To Capture The Only Time Into The Database

Jun 7, 2006

I've a textbox that displays the current time in this format "hh:mm:ss tt" but when it is save into the database it'll display the date and time together. So how do I save only the time into the database? My codes is as shown below:
 
txtTime.Text = DateTime.Now.ToLongTimeString()
Dim parameterDate As SqlParameter = New SqlParameter("@Date_5",SqlDbType.DateTime)
parameterDate.Value = txtDate.Text
objCommand.Parameters.Add(parameterDate)
 
I've tried using Format() but it still get the same results. Can someone help me out? Thanks!

View 1 Replies View Related

Log Reader And Login Capture

Aug 31, 2001

Is there a way I can view the transaction log mean I want to see the transactions occurred during the last few hours before the commit? And is there a way to capture all the logins who access the DB

View 1 Replies View Related

Capture File To Email

Apr 7, 1999

Does anybody know of a way to set up a task which will send an email with an attachment other than using sp_sendmail. Sp_SendMail will run a query and send the results as a text file. But I need to run a stored procedure which generates an Excel spreadsheet then have an email sent with the Excel file as an attachment. The sp_sendmail text file just doesn't work with the information I am generating so I need to find another solution.

Thanks for any help.

View 1 Replies View Related

How To Capture SQL User Login ?

Sep 22, 1998

I am trying to find a easy way of capturing the SQL user login that is being used for the the record row that is being added/updated. I am now using a insert and update trigger to update the last edit date and record add date. Is there a way I could incorporate the user login capturing within the triggers ???

Thanks for any assistance,

Steve

View 1 Replies View Related

Profiler To Capture Sql For 1 Table

Jan 8, 2008

Using SQL Server 2000

I have to leave a production trace running for a couple of days to track down a little bit of data corruption. I am setting the stop time and maximum file size and I am running it from another machine and writing to a file and not a table and all of that good stuff.

however since I am going to be leaving this running for a while I do not want to deal with a gigantic file to sift through I am trying to limit my trace to all of the stored procs, which can be coming from other databases, to those inserting and and updating a particular table.

I have been goofing around with the Objects:Closed and Objects:Open and the SP:Starting And SP:Completed events, but I can not seem to make this work. I skimmed through the first 5 pages of my google search and my BOL search, but came up empty.

Is this possible? I thought I had done this before.

View 2 Replies View Related

Capture Logout Time

Nov 16, 2011

I need to capture the logout time and login time. I can capture the login time already but I cannot capture the logout time.My logout time and login time need to be on the same entry.This is the coding in the logout button:

Code:
protected void logoutButton_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("SELECT TOP 1 LogId FROM LoggedInUsers where MemberID = @MemberID ORDER BY LogId DESC");
cmd.Parameters.AddWithValue("@MemberID", Session["MemberID"]);
Session.Abandon();
}

I also need to do in global.asax. And this is the coding:

protected void Session_End(object sender, EventArgs e)
{
if (Session["MemberId"] != null)
{
UpdateLoggedInUsersLogoutTime(Convert.ToInt32(Session["MemberId"].ToString()));
}
//string emailaddress = (string)Session["emailaddress"];

[code]....

View 1 Replies View Related

How To Capture The Error Message?

Apr 26, 2004

Is possible to capture the message of error generated in the execution
of a command SQL?

Thanks.

View 2 Replies View Related

Capture Error Msg Into Another Table

Nov 15, 2013

One of my co-worker told me I can do this to capture errors and insert into error table but when I test it, it doesn't work. Here is what I try to accomplish. SQL 2012. In reality, I have more complicate queries than below.

1. Insert data FROM SourceEmployee INTO Employee table and capture emp_id and error msg insert into dbo.##temperror table
2. Continue on the process until no more record. Basically, skip the error records and do a while loop until end of record.

--DROP TABLE dbo.Employee;
CREATE TABLE [dbo].[Employee]
(
[emp_id] [int] NOT NULL,
[last_name] [varchar](20) NULL,
[first_name] [varchar](15) NOT NULL,

[code]....

View 2 Replies View Related

Query From Packet Capture

Apr 22, 2014

I'm trying to organize this SQL query from a packet capture and I'm more of a network/application guy, not so much of a DBA. To me it looks like they are using variables in their query and the "@" is a delimiter.

S E L E C T [ t 0 ] . [ S E C T I O N N A M E ] , [ t 0 ] . [ P A R A M E T E R N A M E ] , [ t
0 ] . [ I N T V A L U E ] , [ t 0 ] . [ S T R I N G V A L U E ] , [ t 0 ] . [ D A T E V A L U E ] , [ t 0 ] . [ I N F R A S T R U C T U R A L ]
, [ t 0 ] . [ S i t e P a r a m e t e r s I d ] F R O M [ d b o ] . [ S I T E _ P A R A M E T E R S ] A S [ t 0 ] W H E R E ( [ t 0
] . [ S E C T I O N N A M E ] = @ p 0 ) A N D ( [ t 0 ] . [ P A R A M E T E R N A M E ] = @ p 1 ) @ 4@ @ p 0 n v a r c h a r ( 3
) , @ p 1 n v a r c h a r ( 1 0 ) @ p 0 4 W e b @ p 1 4 M a x Q u e r i e s

[code]...

View 6 Replies View Related

Capture Header Record

Aug 15, 2007

How t o capture a header record from a flat file and write it to
different table.

It seems that Conditional Split task doesn't work because it detects the different layout and errors out.
any help would be appreciated.
thanks

View 3 Replies View Related

Capture CPU Utilization In TSQL

Jan 2, 2007

Happy New Year everyone!I would like to capture CPU Utilization % using TSQL. I know this canbe done using PerfMon but I would like to run TSQL command (maybe onceevery 5 minutes) and see what is the CPU Utilization at that instant sothat I can insert the value in a table and run reports based on thedata.I have spent a good amount of time scouring google groups but this isall I have found:SELECT(CAST(@@CPU_BUSY AS float)* @@TIMETICKS/ 10000.00/ CAST(DATEDIFF (s, SP2.Login_Time, GETDATE()) AS float)) ASCPUBusyPctFROMmaster..SysProcesses AS SP2WHERESP2.Cmd = 'LAZY WRITER'Problem is this gives me total amount of time CPU in %) has been busysince the server last started. What I want is the % for the instant -the same number we see in Task Manager and PerfMon.Any help would be appreciated.Thanks

View 3 Replies View Related

Capture Existing Table

Jul 20, 2005

I trashed SQL Server2000 when I added the WINXP SP2, and had to reinstallit. When I did, my database(DEV_DATA) remained intact, but when I go inthru Enterprise Manager, it is not located in the system tree, and istherefore inaccessible. Can anyone suggest how I could get this databaseincluded.

View 4 Replies View Related







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