i m new to .net and db connectivity in .net using sql server....
i want to insert values from into a db test1 from a function register(); where i will pass values the function register
will this syntax work...
public void register(int mc,int pt)
{
SqlConnection conn = new SqlConnection(@ "Data Source=.\SQLEXP RESS;AttachDbFi lename=C:\Inetp ub\wwwroot\WebS ite1\App_Data\t est.mdf;Integra ted Security=True;U ser Instance=True") ;
conn.Open();
SqlCommand command = new SqlCommand("ins ert into test1 values(mc,pt)", conn);
command.Execute NonQuery();
conn.Close();
}
b"cos this syntax gives a error:
System.Data.Sql Client.SqlExcep tion: The name "mc&quo t; is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
at System.Data.Sql Client.SqlConne ction.OnError(S qlException exception, Boolean breakConnection )
at System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion exception, Boolean breakConnection )
at System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct stateObj)
at System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleR esultSet bulkCopyHandler , TdsParserStateO bject stateObj)
at System.Data.Sql Client.SqlComma nd.RunExecuteNo nQueryTds(Strin g methodName, Boolean async)
at System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe)
at System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery()
at FirstService.re gister(Int32 mc, Int32 pt)
is this error...b"cos of sql insert in an ways...if it is wht shld be the correct way to fire the querry...
1 1550
Hi
Checking your insert statments, i think parameter are also included as hardcoded values.Check the insert statments creation in your code.
for eg
"INSERT INTO simplesql (simple_id, simple_text) VALUES (" + param1 + ",'" + param2+ "')"
your insert statements also should be like this
Hope this helps you
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Costa Lino |
last post by:
Hi All,
I have a DataSet with xml file and I want to make a querry like this
DataView dv = new DataView(mytable);
dv.RowFilter = " Impression < ( MaxImpressions) ";
Impression et MaxImpressions is collumns in my table the same querry access
database is working but her is return 0
|
by: Andreas Fromm |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Im building an user database with many tables keeping the data for the
Address, Phone numbers, etc which are referenced by a table where I keep
the single users. My question is, how do I get the "Id"-value of a newly
inserted address to store it in the referencing user table:
|
by: Andrew Sinning |
last post by:
I've spent the last 2+ hours trying to build an update query in order to
repair a database which failed when the recursive methods which I was
previously using (inside an ASP script running on a server) timed-out
because the database got too big. Thank you so much for any help.
table: users
userId (integer)
table: quizzes
quizId (integer)
|
by: A.S.V. Rosales |
last post by:
I've a cached dataview that i want to insert into a MS-
SQL2000 table. I've tried iterating the dataview values on
key and setting the parameters for the SQL-Querry INSERT,
but i only get the first row of the dataview inserted into
my SQL table while there's more than one row present.
I also tried the SqlAdapter, but could not accomplish.
My scenario :
I must put a datatable -> dataview into a cache for
retreival on another occasion...
|
by: Maulik Thaker |
last post by:
Hi ppl,
I have a querry based on ID. Suppose if i have got two primary keys
(ID) and one foreign key (IDREF) in the same attribute, is there a way
to use them.
For example :
| |
by: Clownfish |
last post by:
OK, I'm having a brain freeze.
I have a table like this:
Office Name Phone
----------------------------------
SG Larry 555-1212
SG Moe 553-4444
SG Curly 666-8888
PO Ren 222-9999
|
by: ravips |
last post by:
I have a map<char *,int it does not work consistently. I have used
similar sort of implementation as below:
map<char *,intm1;
map<char *,int>::iterator i;
m1 = 31;
m1 = 28;
m1 = 31;
m1 = 30;
|
by: getmeidea |
last post by:
I have the following tables,
1> employee_master(emp_id int primary key, emp_name varchar(100));
2> employee_salary_payment(salary_rid int primary key, emp_id int, sal_date date, paid_amt int);
The tables, employee_master and employee_salary_payment have one to many relation.
I need to list the salary payment done for the employee having id = 10. Here I use two different querry to work.
Querry 1:
Select em.emp_id, em.emp_name,...
|
by: dipalichavan82 |
last post by:
i came across a article, where it was mentioned if we want a dynamic querry to fire then use parameterized querry
e.g.
string inputcity=textbox.text;
SqlCommand cmd = new SqlCommand("select * from Customers where city=
'" + inputCity + " ' ";
Don't ever build a query this way!
as this leads to hacking.
instaed do it like this:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |