15,743,876 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View Javascript questions
View C++ questions
View Python questions
View Java questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Łukasz Szeszycki (Top 4 by date)
Łukasz Szeszycki
6-Dec-20 10:42am
View
Thank you, bu could you help me how use Parameterized queries? I am beginner programist and i don't have idea
Łukasz Szeszycki
4-Dec-20 16:31pm
View
Deleted
protected void dodaj_Click(object sender, EventArgs e)
{
string ConnectionString = "Data Source= (LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|dane.mdf;";
string sql;
int row;
int ros;
using (SqlConnection con = new SqlConnection(ConnectionString))
{
// sql query
if (sezon.SelectedValue == "2020/21")
{
sql = "select count(*) from zapasy_2020-21 where login='" + Context.User.Identity.Name + "' and odmiana='" + odmiany.SelectedValue + "'";
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
ros = (int)cmd.ExecuteScalar();
con.Close();
if (ros > 0)
{
sql = "select ilosc from zapasy_2020-21 where login='" + Context.User.Identity.Name + "' and odmiana='" + odmiany.SelectedValue + "'";
SqlCommand cmq = new SqlCommand(sql, con);
con.Open();
int ilo = (int)cmq.ExecuteScalar();
con.Close();
sql = "insert into zapasy_2020-21 values (@ilosc) where login='" + Context.User.Identity.Name + "' and odmiana='" + odmiany.SelectedValue + "'";
con.Open();
SqlCommand cma = new SqlCommand(sql, con);
string y = TextBox1.Text;
int z;
z = int.Parse(y);
SqlParameter paramName = new SqlParameter();
paramName.ParameterName = "@ilosc";
paramName.Value = ilo + z;
cma.Parameters.AddWithValue("ilosc", paramName);
int i = cma.ExecuteNonQuery();
con.Close(); // connection close
}
else
{
sql = "insert into zapasy_2020-21 values (@login,@odmiana,@ilosc)";
con.Open();
SqlCommand cmk = new SqlCommand(sql, con);
string y = TextBox1.Text;
int z;
z = int.Parse(y);
cmk.Parameters.AddWithValue("login", Context.User.Identity.Name);
cmk.Parameters.AddWithValue("odmiana", odmiany.SelectedValue);
cmk.Parameters.AddWithValue("ilosc", z);
int i = cmk.ExecuteNonQuery();
con.Close(); // connection close
}
}
else
{
sql = "select count(*) from zapasy_2021-22 where login='" + Context.User.Identity.Name + "' and odmiana='" + odmiany.SelectedValue + "'";
SqlCommand cmw = new SqlCommand(sql, con);
con.Open();
row = (int)cmw.ExecuteScalar();
// cast into integer and executescalar() get single value from database.
con.Close(); // connection close
if (row > 0)
{
sql = "select ilosc from zapasy_2021-22 where login='" + Context.User.Identity.Name + "' and odmiana='" + odmiany.SelectedValue + "'";
con.Open();
SqlCommand cmp = new SqlCommand(sql, con);
int ilo = (int)cmp.ExecuteScalar();
con.Close();
sql = "insert into zapasy_2020-21 values (@ilosc) where login='" + Context.User.Identity.Name + "' and odmiana='" + odmiany.SelectedValue + "'";
con.Open();
Łukasz Szeszycki
4-Dec-20 16:29pm
View
Yes, i know, but when i write SqlCommand with using , visual shows me a problem with cmd that "an unassigned variable was used". I could send you all my code :)
Łukasz Szeszycki
4-Dec-20 16:10pm
View
when I use this code, shows me an error "an unassigned variable was used" (cmd)