do i have to install database on client's system? [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I am creating a C# Windows Forms application in Visual Studio 2019 for Car Dealing.
My question are:
Should I use local database as only single client on single PC is going to use the app?
Will I have to install database on client's PC?
If there is another way, how can I do it?

Sqlite would be a good solution to this.
https://www.sqlite.org/index.html
"SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bundled inside countless other applications that people use every day."

As NeutralHandle mentioned, you can save the data into SQLite.
To use it in Winforms, you can follow the steps.
1.Install System.Data.SQLite from Nuget
2.Configure the connection string in App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<connectionStrings>
<add name="SQLiteDbContext" connectionString="Data Source=MyDatabase.sqlite" providerName="System.Data.SQLite.EF6" />
</connectionStrings>
</configuration>
3.Then refer to the code demo.
SQLiteConnection.CreateFile("MyDatabase.sqlite");
SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite");
m_dbConnection.Open();
string sql = "create table highscores (name varchar(20), score int)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('Me', 9001)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();// read
SQLiteCommand sqlCom = new SQLiteCommand("Select * From highscores", m_dbConnection);
SQLiteDataReader sqlDataReader = sqlCom.ExecuteReader();
int i = 1;
while (sqlDataReader.Read())
{
listBox1.Items.Add(i);
listBox1.Items.Add(sqlDataReader.GetValue(0));
listBox1.Items.Add(sqlDataReader.GetValue(1));
i++;
}
m_dbConnection.Close();

Related

Retrieve data from database in MYSQL without empty records [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
This post was edited and submitted for review 2 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
In MySql table have data and also have some empty values in the same row. Now I want to display that data into the user without that empty values. I'm not write any code yet
Welcome to Stack Overflow!
1.
I'm not too familiar with C# winforms, but this post can help you establish a connection to your MySQL database where you can query for specific data.
Code taken from that post:
string myConnectionString = "server=localhost;database=testDB;uid=root;pwd=abc123;";
private void button1_Click(object sender, EventArgs e)
{
MySqlConnection cnn = new MySqlConnection(myConnectionString);
try
{
cnn.Open();
MessageBox.Show ("Connection Open!");
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Cannot open connection!");
}
}
Data is retrieved from a MySQL database using a specific SQL (or "Structured Query Language"). In order to learn the basic MySQL syntax for queries, I would recommend a turorial like this.
3.
To send a SQL query to your database (via your established connection in Step 1) I would recommend looking at this post that gives an example on how to send a query via C# winforms
Code taken from that post:
public void Select(string filename)
{
string query = "SELECT * FROM banners WHERE file = '"+filename+"'";
//open connection
if (this.OpenConnection() == true)
{
//create command and assign the query and connection from the constructor
MySqlCommand cmd = new MySqlCommand(query, connection);
//Execute command
cmd.ExecuteNonQuery();
//close connection
this.CloseConnection();
}
}
Overall, you're missing a few steps inbetween C# winforms and MySQL. Different languages USUALLY have an external library that facilitates: establishing a MySQL connection and launching MySQL queries. After obtaining the data from a MySQL query return, its up to you on how to display it to the user!
Hope this helps :D

How to access a SQL database in visual studio? (Razor cshtml, C#) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I Already connected my SQL database with visual studio via server explorer And i filled some tables with values.
Now, I want to access/search through a table from my SQL database in my visual studio project.
For example: in my table i have products from different categories and i only want to display products from a specific category
But, how can in do that?
There is many ways by which you can access.If you are using connected mode Than you have to create object for connection string
SqlConnection con = new SqlConnection(#"Data Source=nameof_server;Initial Catalog=name_of_database;Integrated Security=True");
SqlCommand cmd = new SqlCommand("sql_command",con);
con.open()
//perform action based on your requirment
ExecuteNonQuery() // Use this for insert,update,delete
ExecuteScalar() // Use this for select single column
ExecuteReader() // Use this for select multiple records
con.close()
Please check this link

Get data from remote sql server in a .NET web service [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have created a simple web service in visual studio 2015 with C#. I have set up an sql server database with a table and i want to simply return any value from that table.
By searching i haven't found a very explanatory tutorial.
Should i add a server connection in VS and then use linq or use SqlConnection?
I also included an ADO Entity data model in the project but i don't know how to use it in the webMethod.
Does any good tutorial exist about all options that i have to connect to the db and provide some examples, too?
Since it's a web application I suggest saving the connection string into web.config.
Example:
<connectionStrings>
<add name="ConnStringNameHere" connectionString="Data Source=IPadress;Initial Catalog=databaseName;Integrated Security=False;User ID=name;Password=pass" providerName="System.Data.SqlClient" />
</connectionStrings>
You just have to add the user in SQL Server with the appropriate permissions.
That way you can have a couple of connection strings, each for a user type with specific permissions (some can only read, some can write, etc.)
You make a connection to the database with this simple code:
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connStringName"].ConnectionString))
using (SqlCommand cmd = new SqlCommand("SELECT * FROM user WHERE userName = username", connection))
{
connection.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
string id = (string)reader["Id"].ToString();
//work here
}
}
connection.Close();
}
And a useful link: http://www.codeproject.com/Articles/837599/Using-Csharp-to-connect-to-and-query-from-a-SQL-da

Jira Integration in C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am very new to this.So pardon me if I make any mistakes.
I am trying to read the Jira database.I just need to read it.
No write operations will be involved.
I am using C#.From what little I know, I think a connection has to be established with the Jira database using
SqlConnection conn=new SqlConnection(connectionstring);
And then I can read data using SqlReader.I have tried searching through the database and found few links like http://www.codeproject.com/Tips/762516/Connecting-to-Jira-using-Csharp
But I am not being able to understand.Can anyone help me out or direct me to few resources.
In the links that I searched through there are terms like "Rest API" etc. Do I need to know them ?
If you have access to the database, and want to read data that way, that's entirely possible using standard .NET objects, but you'll probably need to be decent at SQL to get the data out that you want.
Here's how you can (try to) access the database:
SqlDataReader rdr = null;
SqlConnection conn = new SqlConnection("YOUR_CONNECTION_STRING_HERE");
SqlCommand cmd = new SqlCommand("select * from whatever_jira_table", conn);
rdr = cmd.ExecuteReader();
//look up how to read from a reader
conn.Close();
conn.Dispose();
Another option is to use a Jira API which it looks like you can get from NuGet through Visual Studio. If you go this route, you need access to the Jira REST API, and it will expose a more friendly (different?) way to access data.
Either way, just go into Visual Studio, make a console app, and start adding code and stepping through with the debugger until thing start making sense.

How to call code from SQL in C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two classes in which the teachers have merged their final projects into one, one class is software engineering and another one is data bases. The thing is that for SE i have to develop a desktop/smartphone app and for DB i have to develop every DB related stuff for that app.
But i have to keep both things separated, i mean i have to keep C# code away from SQL code so i can't do queries or any stuff using selection strings and such, i just have to call stored procedures with said queries from code.
Any idea how could i do that? To summarize i just want to call any code or procedure that i write in sql and store it's values in a variable,object or array.
As i said i cannot use:
string selectstr = "SELECT * FROM students;"
and execute that query, i have to write that in sql and call it from C# and store the values returned.
Stored procedures are called like any other SQL command in C#:
using (SqlCommand cmd = new SqlCommand("MyStoredProcedure", connection))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#myParameter1", value);
...
using (SqlDataReader reader = cmd.ExecuteReader())
{
...
}
}
The "magic" bit is to set the command type correctly ;-)

Categories