How To Get The Last Record From The Database?
Oct 27, 2007
hi friends,
i tried to get the last record in a specified column from a database. but it fails.
for example, i have a column name as "empid" in the table name "detail". in that, the records are in the form of "Emp1, Emp2, Emp3, ............Emp12."
i used this query --> select top 1 empid from detail order by empid desc
it is showing only Emp9.
it should show Emp12.
but the id's are showing in ascending order(Emp1,2,3,......12) when i used this query --> select empid from detail
i've a gridview to show all Employee id's with paging(1-10 per page). So Emp12 would be showed in the second page. how to get that value "Emp12" from that gridview?
but i need a SQL query rather than this method (getting from gridview).
its urgent. Plz .........................
View 6 Replies
ADVERTISEMENT
May 12, 2014
,I am creating a database where each record is required to have a twin record in the database.These is a type a value and a type b value and both must be present for the record to be valid.
Customer_ID, Order_Type, Product_Code
54, a, 00345
54, b, 00356
Is this something that would have to be done programmatically, or is it possible to create a constraint of some sort to ensure this?
View 8 Replies
View Related
Jan 22, 2008
Hi guys, may I know is it possible to create an update trigger like this ? Assuming there are two database, database A and database B and both are having same tables called 'Payments' table. I would like to update the Payments records on database A automatically after Payments records on database B had been updated. I can't use replication because both tables might having different records and some records are the same. Hope can get any assistance here, thank you.
Best Regards,
Hans
View 8 Replies
View Related
Aug 10, 2005
is it possible to insert record into second database from a stored procedure which is in first database?
View 1 Replies
View Related
Nov 10, 2006
this is my first time used M.Access, so i not very sure is it Access do not have a record id that it will auto generate itself one when i insert a record? if i cannot find.. what is the way that i can enable it?
View 4 Replies
View Related
Oct 30, 2006
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.
View 4 Replies
View Related
Jan 26, 2007
My problem is related to database and data.
I building a project in ASP.NET 2.0 with the help of VWD in which i have certain records and each record has
a unique id with it.Now my problem is that when a user wants to edit a certain record i want the user to enter
a record id for that record. Now if the record id matches any record in the database then that record should be
dislayed in another page with and edit option with it.
View 1 Replies
View Related
Jan 9, 2008
hai everybody!!!!
am developing one application in visual 2005..and sql server.
so how to write the coding for searching one record from a database table according to the id..and to display it
View 1 Replies
View Related
Jan 9, 2008
hai everybody!!!!!
am working wirh visual 2005 and sql server()asp.net).....so i need the coding in VB for searching one record from a database table according to the id..and want to display it.....
View 2 Replies
View Related
Feb 26, 2008
HI How to get 100 ,500 and 1000 or (any particular record) record fromDatabase .Shafqat Soomro
View 3 Replies
View Related
May 4, 2004
Hello,
I was stuck when update database using SqlDataAdapter. I have several textboxes in my webform1. When wepform1 is loaded, they will display user's information. The user can only input content in two textboxes. When user clicks the update button, I hope to update this record in SQL Server 2000 database. However, the program didn't work. There was no error message reported but when I stepped into the code, I found out that dataadapter's update method didn't succeed. I got 0 rows affected. Can I get some advice from someone ?
Here is the code:
string StrUpdateCmd = "Update Table1 Set Hphone = @Hphone, Cphone = @Cphone, Team = @Team Where emailname =@emailname ";
SqlDataAdapter UpdateDa = new SqlDataAdapter("Select * from Table1",SqlConnection1);
UpdateDa.UpdateCommand = new SqlCommand(StrUpdateCmd, SqlConnection1);
//Add parameters of update command.
SqlParameter prm1 = UpdateDa.UpdateCommand.Parameters.Add("@Hphone",SqlDbType.NVarChar, 16);
prm1.Value = txtHphone.Text ;
SqlParameter prm2 = UpdateDa.UpdateCommand.Parameters.Add("@Cphone",SqlDbType.NVarChar, 16);
prm2.Value = txtCphone.Text ;
SqlParameter prm3 = UpdateDa.UpdateCommand.Parameters.Add("@Team",SqlDbType.NVarChar, 16);
prm3.Value = this.DropDownList1.SelectedItem.Value ;
SqlParameter prm4 = UpdateDa.UpdateCommand.Parameters.Add("@emailname",SqlDbType.NVarChar, 50);
prm4.Value = txtEmail.Text;
try
{
DataSet dataset2 = new DataSet();
//Open database connection.
SqlConnection1.Open();
dataset2.Clear();
UpdateDa.Fill(dataset2, "Table1");
this.DataGrid1.DataSource = dataset2.Tables[0] ;
DataGrid1.DataBind ();
//Update database
int ret =UpdateDa.Update(dataset2,"Table1");
if( ret == 1 )
{
ShowMessage("Update succeed!");
}
else
{
ShowMessage("There is an error in updating ");
}
UpdateDa.Fill(dataset2);
//Show data after update.
this.DataGrid1.DataSource = dataset2;
DataGrid1.DataBind ();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlConnection1.Close();
}
View 1 Replies
View Related
Feb 18, 2006
hi, i have no problem to select all records from the table, but how to copy or move these selected records to other table which contain same field as the orriginal.thanks
View 5 Replies
View Related
May 29, 2006
I'm trying to make a website that people can upload file to the server, then the webpage will automatically insert the username and the file name into the database. I have thought about this for couple days but still got nothing. can some one help me?
can some one post a very simple aspx file that can insert a record to the sql database with C#? Not the code that generated by ASP.net 2.0!
I want to see how to access the database manually.
Thank you.
View 2 Replies
View Related
Aug 26, 2004
Hi,
I have a sql server database with 250 tables in it, i wanted to find one particular value from one of the tables in the database. How to find that appreciate your help..
Thanks
View 1 Replies
View Related
Mar 22, 2006
SOS
I am working with SQL 2000 located on a Networksolutions server and I have a Test record I inserted manually, but I am unable to insert a new record and get this error "can't insert new record to database".
No doubt this is a no brainer, but I can't solve it.
Many Thanks
Who ever you are.
View 7 Replies
View Related
Jan 31, 2007
hi. we have 1 production database and a 2nd backup database. one of our users accidentally deleted a case and we would like to get it back. our production database is updated nightly so none of the case's information would've changed.
how can i insert the data from the backup database to the production database? i need to copy one row. thanks for your help!
View 1 Replies
View Related
Jul 20, 2005
I has a strange question.My company is using a old system with Win NT 4.0 Server + MS SQL 7.0.The system is busy and handle a lot of SELECTs and INSERTs all the time.Sometimes, some transactions are blocked by some other transactions.For those INSERT transactions, we usually call a stored procedure and passparameters in to do the INSERT, at the end of the INSERT stored procedure,we always check @@ERROR = 0 and retrieve the @@IDENTITY (it is usually theauto number primary key) to confirm the INSERT is success. But the strangethings is, sometimes, @@ERROR is equals to 0 and I can get a value from@@IDENTITY but when I fetch the record by the primary key (the value of@@IDENTITY) it returns nothing!! The record is disappear and the primarykey is skipped! I found that this happens usually when the INSERT executeat the time when some other transactions are blocking. Anyone knows why therecord is disappear while @ERROR = 0 and the stored procedure can returnvalue from @@IDENTITY?? Anyone has such case happen in their server aswell? Please tell me some solutions on how to solve this, thank you x10000000 times.
View 10 Replies
View Related
Sep 21, 2006
i m using sql server 2000 with asp.net with c#
i hv 4 customer records in the customer table starting from C1001 to C1004, i wanna ask is that when a new record is add to the table, the record will be placed at the bottom of the table. For example,
CustomerID
Customer ID
C1001
C1002
C1003
C1004
C1005
When i add a new record which is C1005, is it the record will be placed as shown in the table?
if so, that's mean can straight away use the datarow to retrieve the largest number which is C1005, right??? Thx
View 1 Replies
View Related
Feb 26, 2007
Hi! i ask you some help..I should build a simple INSERT FORM in a SQLExpress database..
but clicking ADD I have this error :
Incorrect syntax near '='.
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 '='.Source Error:
Line 38: conDatabase.Open()
Line 39:
Line 40: cmdInsert.ExecuteNonQuery()
Line 41:
Line 42: conDatabase.Close()
some solution?
the source code:
<%@ Page Language="VB" Debug="true"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Button_clic(ByVal s As Object, ByVal e As EventArgs)
Dim conDatabase As SqlConnection
Dim strInsert As String
Dim cmdInsert As SqlCommand
Dim myExecuteQuery As String
Dim myExecuteCmd As SqlCommand
conDatabase = New SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=C:Inetpubwwwroot esiApp_Datadatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
strInsert = "Insert pubblicazioni (Nome, Cognome, Titolo) Values = (@Nome, @Cognome, @Titolo) "
cmdInsert = New SqlCommand(strInsert, conDatabase)
cmdInsert.Parameters.Add("@Nome", txtNome.Text)
cmdInsert.Parameters.Add("@Cognome", txtCognome.Text)
cmdInsert.Parameters.Add("@Titolo", txtTitolo.Text)
conDatabase.Open()
cmdInsert.ExecuteNonQuery()
conDatabase.Close()
Response.Redirect("success.html")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>iNSERIMENTO</title>
<LINK href="mauro.css" rel=stylesheet>
<script type="text/javascript" language="javascript">
<!--
function popopen(){
window.open("upload/upload.aspx","name"," toolbar=no,directories=no,menubar=no,width=300,height=300,top=100,left=150,resizable=no,scrollbars=yes");
}
// -->
</script>
</head>
<body bgcolor="#DFE5F2" style="font-size: 12pt">
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" BackColor="#8080FF" BorderColor="Black"
ForeColor="Black" Height="29px" Text="FORM INSERIMENTO DOCUMENTO" Width="371px" Font-Bold="True" Font-Names="Verdana" Font-Size="14pt" Font-Underline="True"></asp:Label><br />
<br />
<br />
<B><span style="font-family: Verdana">NOME </span></B>
<asp:TextBox ID="txtNome" runat="server"></asp:TextBox>
<B><span style="font-family: Verdana">COGNOME </span></B>
<asp:TextBox ID="txtCognome" runat="server"></asp:TextBox><br />
<br />
<B><span style="font-family: Verdana">TITOLO </span></B>
<asp:TextBox ID="txtTitolo" runat="server"></asp:TextBox><br />
<br />
<a href="javascript:popopen()">CARICA DOCUMENTO</a><br/><br />
<asp:Button ID="Button1" runat="server" OnClick="Button_Clic" Text="ADD" Font-Bold="True" Font-Names="Verdana" Font-Size="12pt" Width="160px" /></div>
<br><br>
</form>
</body>
</html>
View 2 Replies
View Related
Jan 27, 2008
Hello, i currently have a gridview component displaying data from a SQLSERVER2005 database. I have created an 'edit' hyperlink on each record so that when pressed, the primary key of a record is sent in the querystring to another page when pressed. example http://localhost/Prog/EditAppointment.aspx?AppointmentId=1
In the edit page, i have dragged and dropped a sqldatasource that contains the select and update statements. i would now like to use textboxes and dropdowns to display the data for the particular record selected (in this case appointmentid=1). however i dont want to use a formview or automated component, just to drag and drop the textboxes myself. how do i bind the textboxes in the HTML code to the data from the select statement? My current select parameters look as follows.
<SelectParameters>
<asp:QueryStringParameter Name="AppointmentId" QueryStringField="AppointmentId" Type="Int32" />
<asp:ControlParameter ControlID="Textbox1" Name="PatientNo" PropertyName="Text" Type="String" />
</SelectParameters>
Perhaps there is an error in my select parameters or does the problem lay elsewhere? Any help would be appreicated.
Thanks,
James.
View 1 Replies
View Related
Apr 7, 2008
Hi i have a very annying problem that i cant seem to solve by myself. I have developed a content managment system for a webpage where people can manage the page. It's almost done except for the fact that i cant seem to delete records from my sql express database.
To access the database i use an sql login in my code to delete witchever record is retrived from a querystring in the URL field. Below is a sample of my delete code when a button is pressed. protected void ButtonDelete_Click(object sender, EventArgs e)
{
string dID = Request.QueryString["dID"];
string myConnectionString = @"Data Source=SRVWEBSQLEXPRESS;Initial Catalog=se;User ID=xx;Password=xx";
SqlConnection myConnection = new SqlConnection(myConnectionString);
string myDeleteQuery = "DELETE FROM drift WHERE dID = @dID";
SqlCommand myCommand = new SqlCommand(myDeleteQuery);
myCommand.Parameters.AddWithValue("dID", dID);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
Response.Redirect("list.aspx");
}
When the i run the code on my development machine located at 10.12.0.80 and the server is located at 10.12.1.65 and this is where the databse is located. The strangest thing is that when i press my deletebutton while debugging in VS2008 on my devmachine the record is deleted! BUT when i run the code live on the server i get an error. See the below log file taken from the windows 2003 server application log.
Event Type: InformationEvent Source: ASP.NET 2.0.50727.0Event Category: Web Event Event ID: 1314Date: 2008-04-07Time: 10:26:45User: N/AComputer: SRVWEBDescription:Event code: 4011 Event message: An unhandled access exception has occurred. Event time: 2008-04-07 10:26:45 Event time (UTC): 2008-04-07 08:26:45 Event ID: 8bdda96aeee44448b570891c593bdb3e Event sequence: 242 Event occurrence: 1 Event detail code: 0 Application information: Application domain: /LM/W3SVC/1015505475/Root-1-128520196339603398 Trust level: Full Application Virtual Path: / Application Path: C:wwwwebsite Machine name: SRVWEB Process information: Process ID: 5156 Process name: w3wp.exe Account name: NT AUTHORITYNETWORK SERVICE Request information: Request URL: http://website/cms/drift/editdrift.aspx?dID=19 Request path: /cms/drift/editdrift.aspx User host address: 10.12.1.1 User: webmaster Is authenticated: True Authentication Type: Forms Thread account name: NT AUTHORITYNETWORK SERVICE
Could anyone help me solve this problem. Thanks.
View 3 Replies
View Related
Feb 3, 2004
When I try to build my solution, it tells me that "SQLCommand" is not defined.
What's the problem?
Sub submitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'If Page.IsValid Then
Try
Dim MySQL = "addCustomerSQL"
Dim cmd As New SQLCommand("addCustomerSQL", dbConn)
cmd.Commandtype() = CommandType.StoredProcedure
cmd.Parameters().Item("@username").Value = userText.Text
cmd.Parameters.Item("@password").Value = passText.Text
dbConn.Open()
cmd.ExecuteNonQuery()
dbConn.Close()
Catch ex As Exception
End Try
End Sub
View 5 Replies
View Related
Dec 7, 2005
Got a question here and as I am no expert programmer, this should be easy for you gurus. I have this fairly generic code I've created where I return data from an SQL table in a DataList control. I want to take it to the next level and return only the last record in the table, but I am unsure of how to do that. Perhaps I shouldn't even be using a DataList control, I'm not sure.
View 2 Replies
View Related
Dec 14, 2005
In my asp.net page when I run a query against the database the datagrid get populated with only the records that starts with the first letter for example A good day. But none of the records that starts like this "A fine day" or "A nice day" displays in the datagrid. I tried to replace the Double Quote but it still returns only the records without " quotes. My query looks like this:
Dim queryString As String = "SELECT [Articles].[AN], [Articles].[Department], [Articles].[ArticleHeading], [Articles].[AccessLevel], [Articles].[Status] FROM [Articles] WHERE (([Articles].[AccessLevel] <> 'SysAdmin') AND ([Articles].[Status] = 'Enable') AND (REPLACE([Articles].[ArticleHeading], 'chr(34)', '')) like @ArticleHeading) ORDER BY [Articles].[ArticleHeading]"
View 6 Replies
View Related
Dec 31, 2007
I have a SQL database that gets populated by another program. Is there a way to determine when a new record is added to that database?
Thanks
View 4 Replies
View Related
Feb 25, 2008
Can I do something like this in RS -
I would like to call a function in a calculated field like
=code.GetNHW(Fields!id1.Value,Fields!date1.Value)
where the GetNHW() function would return a double value based on some conditions-
The code I would like to write in Code window-
Public Function GetNHW(ByVal ID As Integer, ByVal attDate As Date) As Double
Dim dsDTConfig As New DataSet
Dim NHW As Double
dsDTConfig = GetDS("tblEmployee_DailyTimingsConfig", "id=" & ID & " and '" & attDate & "' between configStartDate and configExpiryDate", False)
If dsDTConfig.Tables(0).Rows(0)("allowUnscheduledBreaks") = True Then
NHW = 0.01
ElseIf dsDTConfig.Tables(0).Rows(0)("allowUnscheduledBreaks") = False Then
NHW = 0.05
End If
Return NHW
End Function
What I am looking for is - I would want to get the record(dataset) within the function from the database
and based on the values got, I would check few conditions and calculate NHW.
--Anand
View 4 Replies
View Related
Feb 13, 2008
Let's imagine some situation in MS SQL 2005:
Table t_sample with single column SampleString of type varchar(200). If to this column will be inserted value containing 4 chars, real record (not column) size in database would be 4 or 200? In other words: do MS SQL 2005 records have always constant size (total size of all columns max sizes) or real size of record depends on actual size of inserted data?
View 6 Replies
View Related
Mar 6, 2006
How to check if a record is already in the database I want to import to before importing?
My table have 2 primary key, and the DTS is suppose to be schedule to run every night, though it can be run whenever a user want to get the most updated data.
View 3 Replies
View Related
Aug 2, 2007
Hi friends
I have a bit problem here
Just I want to get back all deleted record of database
How do I perform this task?
If It is possible then plz help me out?
Thanks in Advance
Khan
View 4 Replies
View Related
Oct 22, 2007
Hi.
I have a table where I need to set some rows to Read only (to protect the rows from being edited). Can I do this with a trigger checking against a column (where dataReadOnly = 1)?
Or is there a better way?
thankyou
View 6 Replies
View Related
Sep 7, 2006
hii I have to insert some data into a table from the webpage. For that I need to know the last occurred value in the primary key and increment this by one and then insert the new record into the table. I am working with SQL Server 2005. I am coding in VB and ASP.NET 2.0. How will I go about this?? Is there some easy way for me to knw the last value of the primary key n then insert the record. It would be great if I get the idea more clear with the help of some code... Thanks
View 2 Replies
View Related
Apr 6, 2007
I don't work much with the back end of software development so there is a lot about SQL Server I do not know.
We are building a database. The database will have about 10 tables in it. 3 of these tables will probably have a huge amount of data in them. Specifically each one of the 3 tables will each have about a half a million database records in it. Each record is about 100 characters max in length.(Im am including numbers as characters and summing the individual columns/fields to come up with 100).
Will a SQL server database table with A half a million records in it be possible? We have tried to normalize the database to cut down on the size of the table but it all comes out to about a half a million records per table.
Any help is deeply appreciated.
Bill
View 1 Replies
View Related
Jun 19, 2007
Is me again,and now i facing problem to retrieve a single record from the database.
here is my code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim user As String user = TextBox1.Text Dim varpassword Dim mydata As SqlDataSource
mydata.SelectCommand = "Select * from tbluser where uLogin = '" & user & "'" varpassword = mydata.SelectCommand.uPassword
End SubEnd Class
but i get the error : 'uPassword' is not a member of 'String'
i wan to retrieve the password of that user,can anyone help me?
thanks
View 3 Replies
View Related