Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Tuesday, March 27, 2012

@@Identity c# help...

I am trying to follow other examples I have seen on the site, and am still getting the

Must declare the scalar variable "@.@.INDENTITY".

string sqlAdd =string.Format("INSERT INTO " + siteCode +"_campaign_table (campaign_name, prod_id, type) "

+

"VALUES('{0}', '{1}', '{2}'); SELECT @.@.INDENTITY", campaignName, prodID, type);SqlCommand comAdd =newSqlCommand(sqlAdd, con);

comAdd.CommandType =

CommandType.Text;

con.Open();

//comAdd.ExecuteNonQuery();int identity;

identity =

Decimal.ToInt32((decimal)comAdd.ExecuteScalar());

lblErrorMessageAdd.Text = identity.ToString();

con.Close();

You have a typo. It should be@.@.IDENTITY

Also, your code should use parameters; what you have currently (placeholders for string replacement) is insecure and subject to SQL injection attacks.|||thanks, Corrected a few things there and works as intended.|||Actually, since you are using SQL Server, the best idea is to SELECT SCOPE_IDENTITY(). See, for example, this blog post for an explanation:SCOPE_IDENTITY() and @.@.IDENTITY Demystified. I should have pointed this out on my last post; I am sorry for missing it.

Monday, March 19, 2012

.sql control string

My development environment includes Visual Web Developer, SQL Server 2005 Express and SQL Server Management Studio Express. I have a .sql control string that creates a database. The control string is in my App_Data folder within my web site. When I use SQL Server Managment Studio Express to run the .sql control string and create the tables etc. it does it in my SQLEXPRESS folder and not in the web.

How do I run the .sql file so it will create the database in my App_Data folder within the web site?

Thanks,

Kyleq

Hi Kyleq,

Please make sure that your SQL Server Management Studio Express has connected to the correct database.

A simple .mdf file cannot be working properly, we must

1. Attach it to a SQL Server instance.
2. Connection the SQL Server Management Studio Express to that instance and to that database.
3. Run the .sql scripts.
4. Detach the database.

Please read the following for more information:

http://msdn2.microsoft.com/en-us/library/ms228037.aspx

HTH. If this does not answer your question, please feel free to mark the post as Not Answered and reply. Thank you!

Tuesday, March 6, 2012

.NET Complication (CTS)

class student
{
public string name;
public student(string a)
{
name=a;
}
}
what will be the output of the class in cts?As of your declaration -- nothing.
This is just the constructor for the class ?!
HTH, jens Suessmeyer.|||Hello Aditya,

> class student
> {
> public string name;
> public student(string a)
> {
> name=a;
> }
> }
> what will be the output of the class in cts?
If you're asking, "what does an instance of this class look like when I sele
ct
it from a table", that'll depend on the actual data, but it should be a stri
ng
of hexidecimal values.
If you're asking, "what do I get when I declare a T-SQL variable of this
type," you get get nothing because this class doesn't implement the INullabl
e
interface which is required for UDTs in SQL Server 2005.
Otherwise, I'm not clear that you're asking...
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/

.NET Client connecting to MSDE for the first time

Our app's connection string at most (currently all) client sites points to
Sql Server 7 or 2000 on a seperate machine.
We have one small client who is running MSDE. We tried to bring them up
today.
I cannot get a connection to the MSDE. I keep getting
"System.Data.SqlClient.SqlException: SQL Server does not exist or access
denied."
I removed user id and password and set Integrated Security to True in the
connection string.
Our existing FoxPro app has no problems seeing and using MSDE, the .Net
Client cannot. The MSDE is running on the same machine as the .NET client
and the existing FoxPro application.
The FoxPro app uses an ODBC connection which works.
I googled this and I am not coming up with anything.
Any suggestions?
hi Greg,
Greg Robinson wrote:
> "System.Data.SqlClient.SqlException: SQL Server does not exist or
> access denied."
>
this kind of exception is a generic MDAC raised exception
please have a look at
http://support.microsoft.com/default...06&Product=sql
to see further suggestions..
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.14.0 - DbaMgr ver 0.59.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply