|
After the data gets added to the database, I read and print out the data in nUnit's console from the database. There are times when I can't read all of the data from the table. e.g. if the table has 5 rows, it will sometimes show me only 2 rows. And then there are times, when it would print out incorrect values from the data e.g. if a column has an integer value of '2', it will print out '0'. My guess for this would be that it wasn't able to read the data from that particular column.
What other type of information would you like to know?
|
|
|
|
|
I need to know the ID of a last inserted record. The problems is, that I use VS generated dataset and table adapter, so the classic "SELECT @@IDENTITY" is not working.
I also tried to use "SELECT IDENT_CURRENT('tablename')", but for some reasons it crashes at the runtime, saying that function IDENT_CURRENT is not recognized, or something like this.
|
|
|
|
|
This query select top 1 id from tablename order by id desc will not be choice for you?
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
yeah, it worked. Thank you very much. Still, I have a question: isn't it the same as choosing the maximum ID?
|
|
|
|
|
makumazan84 wrote: Thank you very much.
No problem.
If ID value is increase-able always then we can use max function to get maximum value of ID.
example: select max(id) from tablename
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
This only works in a single user environment - otherwise someone else could insert before you run the select. Also, this relies on id being the prmary key, otherwise you should select the max(id) - bad practice to rely on any ordering unless specified.
Do't know what the answer is though, I nvere use tableadaptors etc, there isn't enough control over transactions etc for the sort of systems I usually work on.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Thanks for your information.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
select max(id) from mytable should be enought but...you may need to use a lock. Read about it i don´t know much about it!
If it´s a read/report procedure (you don´t delete or edit anything) there´s no problem using select max(id )from mytable, otherwise you must use somekind of lock!!!
To prevent users to edit same thing same time
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
hi to all,
i am making an application using windows mobile 5.0 sdk and connecting to sql server mobile edition ........i made the .sdf file using sql server management studio and kept in my application directory ............
string strAppWorkingDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
string connstr = "Data Source=" + strAppWorkingDir + @"\" + "sample.sdf; Persist Security Info=False;";
string connstr = "Data Source=C:\\Documents and Settings\\IT\\sample.sdf; Persist Security Info=False;";
string connstr = "PROVIDER=Microsoft.SQLServer.OLEDB.CE.3.0; Data Source=C:\\Documents and Settings\\IT\\sample.sdf";
string connstr = "Data Source =." + @"\" + "sample.sdf;" ;
SqlCeConnection conn = new SqlCeConnection(connstr);
SqlCeDataAdapter adapter = new SqlCeDataAdapter("select * from table1",conn);
DataSet dst = new DataSet();
adapter.Fill(dst);
textBox3.Text = dst.Tables[0].Rows[0].ItemArray[0].ToString();
i have tried all these connection string but most of the time i am getting an error :-
An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
Additional information: The database file cannot be found. Check the path to the database. [ File name = .\sample.sdf ]
although it is working when connect with wizard ...............................as it keep connections in .xsd........
please can anyone help me out how to connect to .sdf file..............................................
Thanks & Regards
Manish Singhal
Software Engineer
Maxworth systems(Delhi)
|
|
|
|
|
First, of all your question belong to 'Mobile Development' board.
Second, check this link[^]
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
hi,
thanks for ur reply i sorry i must had post it there .............................those strings r not working ..................................can please me some peace of code or application sample ...........
thanks
Thanks & Regards
Manish Singhal
Software Engineer
Maxworth systems(Delhi)
|
|
|
|
|
hi i ma using a query like to select country code using between query cause ip
if im using this query i will fetch value sometime but i will display time out expired error some time.
to over come this problem what can i to do
can share your ideas with me
my query is
SELECT countryShort FROM IPCITYLATLONGISP WHERE '3678433939' between ipFrom and ipTo
with regards,
bretto
|
|
|
|
|
Try to optimize your query.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Have you considered putting an index on this column (you need to consider that while it may speed up your query, it might also slow down your inserts).
|
|
|
|
|
Besides optimizing your query (perhaps by indexing the column) you can increase the query timeout in your code.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Can anyone help me here? i need to use this method
declare @season as varchar(4)
set @season = '2004'
declare @sql1 as varchar(max)
declare @sql2 as varchar(max)
declare @sql3 as varchar(max)
select @sql1 = 'create table driver_'+@season+'(id int, f_name varchar(50),l_name varchar(50))'
exec (@sql1)
declare @id int
declare @f_name varchar(50)
declare @l_name varchar(50)
set @id = 123
set @f_name = 'lewis'
set @l_name = 'hamilton'
select @sql2 = 'insert into driver_'+@season+' values(@id,@f_name,@l_name)'
exec (@sql2)
select @sql3 = 'select * from driver_'+@season
Error msg: Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@id".
Not declared he says!!!
nelsonpaixao@yahoo.com.br
|
|
|
|
|
here it is:
<br />
declare @season as varchar(4)<br />
set @season = '2004'<br />
declare @sql1 as varchar(255)<br />
declare @sql2 as varchar(255)<br />
declare @sql3 as varchar(255)<br />
select @sql1 = 'create table driver_'+@season+'(id int, f_name varchar(50),l_name varchar(50))'<br />
exec (@sql1)<br />
<br />
select @sql2 = 'declare @f_name varchar(50)<br />
declare @l_name varchar(50) declare @id as int set @id = 123 <br />
set @f_name = ''lewis'' <br />
set @l_name = ''hamilton'' insert into driver_'+@season+' values(@id,@f_name,@l_name)'<br />
exec (@sql2)<br />
select @sql3 = 'select * from driver_'+@season
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
thanks i will check it now
I was thinking on doing that has in the before code, didn´t tryed yet
Don´t you know other way?
No need to anser
nelsonpaixao@yahoo.com.br
|
|
|
|
|
I have tested and it has worked for me.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Listen Blue_Boy thanks for the post it woorks fine.
It seems i didn´t need that yet, because i thought on creating new tables and drop them after "my search", so i needed to create tables with diferents names, (because they triggered the same sp code)
But i ended on doing a diferent loop: create 1 table, search it and drop it, created 1 table,search it and drop it etc...
(so i didn´t need diferent table names)
ALL OK, but if i needed to do your way?
I couldn´t manage to do your dynamic sql when i have to enter a sp parameter, like @season.
declare @my_sql varchar(max)
select @my_sql = 'bellow code'
use my_Database
go
create procedure season_standings
@season as char(4)
as
begin
...
end
go
thanks no need to anser
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Hi guys,
We have a column "LastModifiedDate" columns in almost all our tables. We are currently using procedures to update lastupdateddate column. but every now and then developers forget to add this to their query.
Is their a way to make this automatic...should we use triggers for this??...
But again I m not sure if we should add triggers to all tables...
what's the best practice for this?
Any suggestions??
Keep DotNetting!!
GeekFromIndia
|
|
|
|
|
Use triggers. Much better solution than to use separate procedure.
|
|
|
|
|
we are not using separate procs but every procs that updates any table...it updates this column also...
Keep DotNetting!!
GeekFromIndia
|
|
|
|
|
So is every update and insert done via stored procedure and the developers are writing the procedures?
If that is true I would still go to triggers. In this way the database takes care of critical information (I understood that the date must be modified every time) and the developers don't have to remember to add this column to every DML operation. Also DML executed directly against the table is setting the date correctly if triggers are used.
Just wondering how you use the LastModifiedDate. If it simply shows the date when the record is last modified, it's ok. However if you use it for optimistic locking, the resolution isn't adequate.
Mika
|
|
|
|
|
Thanks Mika,
We are using it to update date for any change in the table...i guess i will be using triggers only..
thanks again for help
Keep DotNetting!!
GeekFromIndia
|
|
|
|