SQL Server and Visual Studio 2012 [closed] - c#

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 9 years ago.
Improve this question
I have connected to my database using Data Connection Server Explorer and the same is added to my web.config as well. Now can someone tell me how to query it?

Sure, you could do this:
using (SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["key_of_element"]))
{
c.Open();
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Table"))
{
var reader = cmd.ExecuteReader();
while (reader.Read())
{
// do something with the data
}
}
}

Related

Does Dapper open a connection string even if its not used? [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 4 days ago.
Improve this question
Example:
using (var connection = SqlConnection("DBConnectionString"))
{
C = A.SomeMethod();
}
Does Dapper open up a Connection to the Database in the example case even though there are no calls to the database?
Or is the connection only established when the connection is requested IE:
using (var connection = SqlConnection("DBConnectionString"))
{
C = context.Query("SELECT * FROM UserSecrets");
}

Populate ComboBox control with data from database [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 am doing a c# WFA program. I want the comboBox to be able to display the car brand from the data grid view but I'm not sure how to do that.
See Image
You want it from a database? Then you could try something like this.
string Sql = "select brand from [Car]";
SqlConnection conn = new SqlConnection(#"path_to_db");
conn.Open();
SqlCommand cmd = new SqlCommand(Sql, conn);
SqlDataReader DR = cmd.ExecuteReader();
while (DR.Read())
{
Invoke(new Action(() => ComboBox1.Items.Add(DR[0])));
}

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

C# MySQL DataRow with multiple values [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 9 years ago.
Improve this question
Is there a way to do a c# datarow like the below code in a SELECT * query
//Have results like blow
string username = (string)row["username"];
I've tried but all I seem to see is reader or something, witch I know nothing about and don't understand. Can you lead me to some code that will help or give me a example?
DataReader is actually exactly what you need. The 'DataRow' class by itself won't help you; that gets used as part of a more complex solution, the 'DataSet' class (which uses 'DataTable' and that in turn uses 'DataColumn' and 'DataRow'). I don't see many people using 'DataSet'; if you want something complex with drag-and-drop design, you should look at using Entity Framework.
Here is a standard way to read values from SQL in .NET via DataReader (which, no matter what anyone says, is the fastest way to simply read data from a SQL database in .NET):
using (var connection = new SqlConnection("<Your connection string here>")
{
var command = new SqlCommand(
"SELECT username, email FROM users;",
connection);
connection.Open();
var reader = command.ExecuteReader(); // Using the DataReader (specifically, the SqlDataReader)
if (reader.HasRows)
{
while (reader.Read())
{
Console.WriteLine("User {0} has email {1}", reader["username"],
reader["email"]);
}
}
else
{
Console.WriteLine("No rows found.");
}
reader.Close();
}
MSDN documentation for DataReader

Query String operator assignment error [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 9 years ago.
Improve this question
I'm going to send back data to my sms gateway.first i have a querystring like this.
string mobileNo = Request.QueryString["msisdn"];
int dest = int.Parse(Request.QueryString["shortcode"].ToString());
string messageIn = Request.QueryString["msg"];
string operatorNew = Request.QueryString["operator"];
Then i'm going to assign a variables to it.
public void sendReply(string messageOut)
{
messageOut = "http://mygateway.com/api/mt?msisdn=mobileNo&body=msg&sender=shortcode&key=nvqow9rhfp&product_id=2116&operator=OperatorNew&country=us";
}
But i'm getting operator assignment error..
Check this.This parameter is wrong.this param not supplied.
&body=msg
Please verify your Key & Product id with the gateway owners.

Categories