c# vs2017 Code First与Mysql联系时报错 5C

我在练习写一个code first的demo,连接Mysql数据库。我用migration,在数据库中已经看到了
新生产的数据库和表。说明app.config中填写的数据库连接是没有问题的。引用的包什么的都没问题。

但是每次走到main程序中就会报以下错误,查了很久了没发现原因。请各位大牛帮助
![图片说明](https://img-ask.csdn.net/upload/201805/13/1526198803_611040.png)图片说明

1个回答

getSetting错误,但是没有进一步的信息,初步推测可能是你的配置文件没有写对,或者放错了位置,特别是链接字符串。检查下。

m0_37816464
梅长苏880112 查询过多个帖子。基本确认配置没问题。而且Migration已经通过那个配置,反向生成数据库表了,有问题是不会生成的
大约 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
C#中 使用CodeFirst开发模式有什么好处,和先建数据库有什么区别

**C#**中 使用**CodeFirst**开发模式有什么好处,和先建数据库有什么区别

winform使用EF框架,codefirst创建数据库成功,创建表失败(sqlite)

将已经创建好的数据库删除之后,重新创建就会报错表xxx找不到,必须重新启动应用程序才可以创建成功,详细的删除库方法如下: ![图片说明](https://img-ask.csdn.net/upload/201608/30/1472520442_752341.png) 创建库: ![图片说明](https://img-ask.csdn.net/upload/201608/30/1472520754_257715.png)

使用PHP通过SSL连接到MySQL

<div class="post-text" itemprop="text"> <p>I'm writing my first script that will connect via SSL to a MySQL database. I have been doing a lot of reading on the subject and have come across many options on how to set it up; some that apply to my situation and some that don't. Here is my situation:</p> <p>The MySQL server is on the same machine as the script. My SSL Certificate is installed. Is it secure to simply connect to the database via a page that is using SSL with the following code?</p> <pre><code>Connecting via https://www.mysitehere.com/myscript.php $con = mysql_connect("localhost", "username", "password", MYSQL_CLIENT_SSL); if (!$con) {die('Could not connect: ' . mysql_error());} mysql_select_db("my_database", $con); </code></pre> </div>

从C#Windows窗体调用PHP Web服务

<div class="post-text" itemprop="text"> <p>I am trying to verify username, password, and software token number of a C# Windows Form to values in MySQL database. </p> <p>My C# Code:</p> <pre><code> private void btnlogin_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtusername.Text)) { MessageBox.Show("Please insert username"); } if (String.IsNullOrEmpty(txtpassword.Text)) { MessageBox.Show("Please insert password"); } var username = txtusername.Text; var password = txtpassword.Text; string Token = "28956"; var SoftwareToken = token; WebRequest request = WebRequest.Create("https://mydomain.com.au/Verification.php?username=username&amp;password=password&amp;Token=SoftwareToken"); request.Method = "GET"; WebResponse response = request.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. var responseFromServer = reader.ReadToEnd(); responseFromServer.ToArray(); /*I have tried: responseFromServer.ToArray();(because result on php page is an array. I have tried responseFromServer.ToString();*/ MessageBox.Show(responseFromServer); } </code></pre> <p>My PHP code (Web service):</p> <pre><code>&lt;?php // Database Structure require_once('connect.php'); //Get password from the database for the user $stmtus = $conn-&gt;prepare("SELECT password from `Users` where `email` = :Username"); $stmtus-&gt;bindParam(':Username', $username); $username= $_GET['username'];; $stmtus -&gt; execute(); $password = $stmtus-&gt;fetch(); $un = $_GET['username']; $pw = $_GET['password']; $ust = $_GET['Token']; if(password_verify($pw, $password[0])){ $stmt = $conn-&gt;prepare("SELECT COUNT(Token) AS cnt FROM `SoftwareToken` LEFT JOIN User ON iduser = SoftwareToken.Consultant WHERE Token = '$ust' AND username = '$un'"); $stmt-&gt;bindValue(':Username', $un); $stmt-&gt;bindValue(':Token', $ust); $stmt-&gt;execute(); $result= array(); while($SToken= $stmt-&gt;fetch(PDO::FETCH_OBJ)){ array_push($result, $SToken-&gt;cnt); } echo json_encode($result); } $conn = null; ?&gt; </code></pre> <p>I am battling to understand how I call the web service from the C# application, how do I pass the variables from the C# application to the web service and how do I return the json_encode to the C# application from the web service. </p> <p>I am not a full-time programmer and this is my first encounter with web services. If there are any suggestions on how to improve either of the codes, I would much appreciate. </p> <p><strong>UPDATE</strong></p> <p>I have updated my code as assisted. When I run the php code with variables it runs and gives me a $result (array). A numeral answer 1.</p> <p>When I test my code to display the result in a MessageBox, the MessageBox is empty. Why ?</p> </div>

如何将两个MySQL id传递给c#.exe?

<div class="post-text" itemprop="text"> <p>I am trying to make a PDF form filling program. The program should get 2 id's from the PHP script, search the MySQL database, and fill the forms with info based of those two id's, but i cant make the PHP script pass arguments to the c# executable. Maybe u can help me out :)</p> <p>PHP script :</p> <pre><code>&lt;?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("documente", $con); $idfirma; $idagent; $sql="SELECT * FROM `agenti` WHERE `Nume Agent` = '$_GET[numea]'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { echo "Date agent"."&lt;br&gt;"; echo $row['Nume Agent'];echo " | ";echo $row['Sigiliu'];echo " | ";echo $row['Legitimatie']."&lt;br&gt;"."&lt;br&gt;"."&lt;br&gt;"."&lt;br&gt;"."&lt;br&gt;"; $idagent=$row['ID']; } $sql1="SELECT * FROM `dateclienti` WHERE `Cod Fiscal` = '$_GET[codf]'"; $result = mysql_query($sql1); while($row = mysql_fetch_array($result)) { echo "Date Firma"."&lt;br&gt;"; echo $row['Nume Societate'];echo " | ";echo $row['Adresa Sediu'];echo " | ";echo $row['Cod Fiscal']."&lt;br&gt;"; $idfirma=$row['ID']; } exec("pdfgen\PdfGenerator\bin\Debug\PdfGenerator.exe $idfirma, $idagent 2&gt;&amp;1"); echo $idfirma."&lt;br&gt;"."&lt;br&gt;"; echo $idagent; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con) ?&gt; </code></pre> <p>c# scipt :</p> <pre><code>using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using iTextSharp; using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.xml; using System.IO; using MySql.Data.MySqlClient; namespace PdfGenerator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { FillForm(); ListFieldNames(); } /// &lt;summary&gt; /// List all of the form fields into a textbox. The /// form fields identified can be used to map each of the /// fields in a PDF. /// &lt;/summary&gt; private void ListFieldNames() { string pdfTemplate = @"C:\xampp\htdocs\site\pdfgen\PdfGenerator\form.pdf"; // title the form this.Text += " - " + pdfTemplate; // create a new PDF reader based on the PDF template document PdfReader pdfReader = new PdfReader(pdfTemplate); // create and populate a string builder with each of the // field names available in the subject PDF StringBuilder sb = new StringBuilder(); foreach (DictionaryEntry de in pdfReader.AcroFields.Fields) { sb.Append(de.Key.ToString() + Environment.NewLine); } // Write the string builder's content to the form's textbox textBox1.Text = sb.ToString(); textBox1.SelectionStart = 0; } private void FillForm() { string idagent1 = null; string idfirma1 = null; string[] args = System.Environment.GetCommandLineArgs(); if(args.Length !=0) { idfirma1 = args[1]; idagent1 = args[2]; } using (var connection = new MySqlConnection("server = localhost; User Id = root; password = ; database = documente;")) { connection.Open(); string agenti = "SELECT `Nume Agent` FROM `agenti` WHERE `ID` = @id"; string name1 = null; using (var cmd = new MySqlCommand(agenti, connection)) { cmd.Parameters.AddWithValue("@id", idagent1); MySqlDataReader rdr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(rdr); foreach (DataRow row in dt.Rows) { string name = row["Nume Agent"].ToString(); name1 = name; } string pdfTemplate = @"C:\xampp\htdocs\site\pdfgen\PdfGenerator\form.pdf"; string newFile = @"C:\xampp\htdocs\site\pdfgen\PdfGenerator\completed_form.pdf"; PdfReader pdfReader = new PdfReader(pdfTemplate); PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream( newFile, FileMode.Create)); AcroFields pdfFormFields = pdfStamper.AcroFields; // set form pdfFormFields // The first worksheet and W-4 form pdfFormFields.SetField("topmostSubform[0].Page1[0].regcomert[0]", name1); // flatten the form to remove editting options, set it to false // to leave the form open to subsequent manual edits pdfStamper.FormFlattening = true; // close the pdf pdfStamper.Close(); } } } } } using System; using System.Collections.Generic; using System.Windows.Forms; namespace PdfGenerator { static class Program { /// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt; [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } </code></pre> </div>

MySQL插入/更新问题

<div class="post-text" itemprop="text"> <p>So right now I'm working on a basic session system for my C# Application. I have a table with id,username, password and a session table with id, code, start.</p> <p>the id columns of both tables are relative to the user logged in (id of user table is the same as session table). What I want to do is that when it sets the session it first checks to see if a session is already active, if it is then it will just update the current one, if there isn't one it will insert a new one. This works fine. My problem is that no matter what user I log in as the id is always set to 0 so I can have a max of one session active at a time.</p> <p>Here is what I am currently doing:</p> <pre><code>//get id of inputted user. $id = getUserId($username); //first check if a session already exists that is connected to this username $query = mysql_query("SELECT * FROM sessions WHERE(`id`='$id')") or die("Couldn't query database: &lt;br&gt; &lt;br&gt; " . mysql_error());; if(mysql_num_rows($query) &gt; 0) { //session already exists, update it. mysql_query("UPDATE sessions SET `code`='$code', `start`='$date' WHERE(`id`='$id')") or die("Failed to update session: &lt;br&gt; &lt;br&gt; " . mysql_error()); } else { //session doesn't exist so lets create one mysql_query("INSERT INTO sessions (`id`,`code`,`start`) VALUES('$id','$code', '$date')") or die("Failed to create session: &lt;br&gt; &lt;br&gt; " . mysql_error()); } </code></pre> <p>Also my getUserId function:</p> <pre><code>function getUserId($username) { $query = mysql_query("SELECT * FROM users WHERE(`username`='$username')"); $row = mysql_fetch_row($query); return $row[0]; } </code></pre> <p>My question, if you didn't get it already. Is why is it that the 'id' is always being set to 0 even though the getUserId() function is returning the proper id of the user?</p> <p>Any suggestions?</p> </div>

从PHP获取数据数组并将其传递给C#变量

<div class="post-text" itemprop="text"> <p>I have a c# application that needs to send and retrieve using a PHP file. This PHP file then communicates with the database that the application uses for its data. My problem is, I don't know how to send and get array data between PHP and C#. Below is my code which only process one data, the <strong>student_id</strong>.</p> <p>I tried finding tutorials and solution, and even API's but none could give the exact help I need.</p> <p>Here is my PHP code:</p> <pre><code>class CaptureForm{ ////LOCAL FUNCTION [-&gt;] private function query($sql, $arg, $fetch = false){ require "config.php"; $q = $db-&gt;prepare($sql); $q-&gt;execute($arg); return $fetch ? $q-&gt;fetch(2) : $q; } private function getStud($stud_no){ return $this-&gt;query("SELECT stud_id FROM tbl_students WHERE stud_id COLLATE latin1_bin LIKE ?", array($stud_no), true)["stud_id"]; } ////LOCAL FUNCTION [&lt;-] public function ShowStud($stud_no){ if(empty($stud_no)) return "ERROR:MISSING_PARAMETERS"; return $this-&gt;query("SELECT first_name FROM tbl_students WHERE stud_id = ?", array($this-&gt;getStud($stud_no)), true)["first_name"]; } ////USER FUNCTION [-&gt;] public function CheckWork($stud_no){ //=login if(empty($stud_no)) return "ERROR:MISSING_PARAMETERS"; return "OK:LOGGED_IN"; } </code></pre> <p>and this is my C# code:</p> <pre><code>private void btn_in_Click(object sender, EventArgs e) { if (Execute("CheckWork", "stud_no=" + stud_num.Text) == 1) { stud_no = stud_num.Text; //To pass it to any other froms (=global) //same for pass WebClient fetchInfo = new WebClient(); string studno = fetchInfo.DownloadString("http://localhost/server_api/clog.php?action=showStud&amp;stud_no=" + stud_no); if (studno == "Michelle") { MessageBox.Show("You are logged in! Yay!", "Logged in", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("You are logged in!", "Logged in", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } </code></pre> <p>Both codes are working very well but as I said, can only process one data. I expect to have an array of data to be sent to PHP then to the database and back from PHP to C# then output it as broken down strings. You can send the answer if you know or any other solution/tutorial that you can give. Thank you very much!!</p> </div>

winform开发VS2012使用ADO添加实体模型 相关

连接MySql数据库,选择相应的数据库表。生成的edmx文件下多了两个tt文件,Designer中无数据,翻阅网页:删除两个tt文件,设置edmx的属性——代码生成策略改为默认值; 然后实例化生成的entities: 例如: using (Entities en = new Entities()) { var lst = en.party_businesspartners.First(s => s.id == Guid.Parse("0813ccc3-903a-11e1-89c8-5cf3fc4a687c")); } 抛出异常未将应用对象设置到对象实例…… 请大家多多发言,多多指点……

abp数据库迁移产生的问题

在程序包管理控制台运行: Add Migration InitialCreate ,生成的文件删除后如何重新添加 注:删除部分文件后:重新 Add Migration InitialCreate后, pm>update-database 数据库,因为找不到部分已经删除的部分文件内容报错

too long

<div class="post-text" itemprop="text"> <p>I'm building a simple application that requires login. At the moment I'm connecting to my database directly from my C# application however, the college network on which this will be used doesn't allow direct connections to MySQL for some reason. I decided to take a look at how I would do this from PHP instead. I've build a simple login form and tested it and it seems to work. However I have some questions and issues that need sorting out.</p> <p>How would I first of all stop just anyone typing in the address of the PHP file and getting the data back?</p> <p>Second, how will I be able to get multiple results back? Let's say I make a PHP file that gets all of the user's files and stores them in the C# application, how do I actually parse this from the PHP file?</p> <p>Here is an example of a login.php file I would have on the server:</p> <pre><code> &lt;?php include("connect.php"); $username = mysql_escape_string($_GET['username']); $password = mysql_escape_string($_GET['password']); $squery = mysql_query("SELECT * FROM users WHERE username='$username'"); $query = mysql_fetch_array($squery); $rowcount = mysql_num_rows($squery); if($rowcount == 1) { if($password != $query['password']) echo'Password errata'; else echo 'Login avvenuto'; } else echo 'Account non registrato'; ?&gt; </code></pre> <p>And here is the code I'd use on C# to access the PHP file:</p> <pre><code>string Reply = new WebClient().DownloadString("http://127.0.0.1/ClipCloud.Service/account_auth/login.php?username=" + textBox1.Text + "&amp;password=" + textBox2.Text); switch (Reply.ToLower()) { case "account non registrato": { MessageBox.Show("Account not registered!"); break; } case "password errata": { MessageBox.Show("Password error!"); break; } case "login avvenuto": { MessageBox.Show("Login happened!"); break; } default: { MessageBox.Show("Error with the remote server, please let try again later!"); break; } } </code></pre> <p>Sorry if this question is a bit confusing, I basically just need to know how to correctly manipulate a database with PHP using C# with correct security in place.</p> </div>

如果第一行不为空,如何将值插入第二行? 数据库

<div class="post-text" itemprop="text"> <p>I should insert value to <code>parnerCode2</code> if <code>parnerCodeOwner1</code> already taken value;</p> <p>Below code only inserts to <code>parnerCodeOwner1</code> if new values comes it rewrites first one, It shouldn't rewritten, value should inserted to <code>parnerCode2</code></p> <pre><code>&lt;?php if (isset($_POST['partnerCode'])) { // receive all input values from the form $partnerCode= mysqli_real_escape_string($db, $_POST['partnerCode']); if (empty($partnerCode)) { array_push($errors, "CODE required"); } $user_check_query = "SELECT * FROM refer WHERE partnerCode='$partnerCode' LIMIT 1"; $result = mysqli_query($db, $user_check_query); $user = mysqli_fetch_assoc($result); if (count($errors) == 0) { $query = "update refer set partnerCodeOwner1= '" . $_SESSION['username'] . "' where randomfield='$partnerCode' "; mysqli_query($db, $query); } } ?&gt; </code></pre> <p></p> <pre><code>ID randomfield parnerCode2 parnerCodeOwner1 +-------+-------------+-------------+----------------+ | 1 | uOxerUg4 | | BuBI9vk | +-------+-------------+-------------+----------------+ | 2 | cZzuJlcs | | uOxerUg4 | +-------+-------------+-------------+----------------+ | 3 | BuBI9vke | | cZzuJlcs | +-------+-------------+-------------+----------------+ </code></pre> </div>

其他信息: Keyword not supported: 'port'

![图片说明](https://img-ask.csdn.net/upload/201705/15/1494834202_942974.png) 如图,跪求各位大神帮忙解决

等待mysql服务器的响应很简单

<div class="post-text" itemprop="text"> <p>I'm new to programming and wrote a basic login script <em>(or rather watched a tutorial)</em>, but my output in Unity is at first "User nicht gefunden" and about one second later "User gefunden". </p> <p>My question: Can I somehow wait for a response from the mysql server in a easy way and still recognize a missing connection?</p> <p>Unityscript:</p> <pre><code>public string inputusername; public string inputpassword; public string URL = "http://localhost/login.php"; void Start () { } void Update () { if (Input.GetKeyDown(KeyCode.L)) { StartCoroutine(LoginToDB(inputusername, inputpassword)); } } IEnumerator LoginToDB(string username, string password) { WWWForm form = new WWWForm(); form.AddField("usernamePost", username); form.AddField("passwordPost", password); WWW www = new WWW(URL, form); yield return www; if(www.text == "wrong") { Debug.Log("User nicht gefunden"); } if(www.text == "correct") { Debug.Log("User gefunden"); } } </code></pre> <p>Phpscript:</p> <pre><code>$servername = "localhost"; $username = "root"; $password = "********"; $dbName = "test"; $user_username = $_POST["usernamePost"]; $user_password = $_POST["passwordPost"]; $conn = new mysqli($servername, $username, $password, $dbName); if(!$conn){ die("Verbindung Fehlgeschlagen!". mysqli_connect_error()); } $sql = "SELECT password FROM users WHERE username = '".$user_username."' "; $result = mysqli_query($conn, $sql); if(mysqli_num_rows($result) &gt; 0){ while($row = mysqli_fetch_assoc($result)){ if($row['password'] == $user_password){ echo "correct"; } else{ echo "wrong"; } } }else { echo"not here"; } </code></pre> <p>Sorry in advance for the probably simple question.</p> </div>

从C#访问php soapservice

<div class="post-text" itemprop="text"> <p>well i wanted to make a simple webservice that searches the db and return the data i know i can do it with mysql connector but this is just to learn how to use soaps here is the code for php soap server </p><pre><code>require_once ('lib/nusoap.php'); $namespace = "http://localhost/webservice/index.php?wsdl"; $server = new soap_server(); $server-&gt;configureWSDL("DBQuery"); $server-&gt;wsdl-&gt;schemaTargetNamespace = $namespace; $server-&gt;register( 'QueryMsg', array('name'=&gt;'xsd:string'), array('return'=&gt;'xsd:string'), $namespace, false, 'rpc', 'encoded', 'returns data from database'); function QueryMsg($query) { $con=mysqli_connect('localhost','root','','webserivce'); if (mysqli_connect_errno()) { return "Failed to connect to MySQL: " . mysqli_connect_error(); } if(!isset($query) or strpos(strtolower($query),'select')&lt;=-1) { return "invalid order"; } else { mysqli_real_escape_string($con,$query); $result = mysqli_query($con,$query); while($row = mysqli_fetch_array($result)) { $data[] = $row;} return json_encode($data); } } // create HTTP listener $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server-&gt;service($HTTP_RAW_POST_DATA); exit(); ?&gt; </code></pre> <p>it works when i try calling it from a php soap client but when i try adding this http:// localhost /webservice/index.php in visual studio as service refernce to consume it from C# application i get an error here it is </p> <pre><code>The HTML document does not contain Web service discovery information. Metadata contains a reference that cannot be resolved: 'http://localhost/webservice/index.php'. The content type text/xml; charset=ISO-8859-1 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 700 bytes of the response were: '&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;&lt;SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"&gt; &lt;SOAP-ENV:Body&gt;&lt;SOAP-ENV:Fault&gt;&lt;faultcode xsi:type="xsd:string"&gt;SOAP-ENV:Client&lt;/faultcode&gt;&lt;faultactor xsi:type="xsd:string"&gt;&lt;/faultactor&gt;&lt;faultstring xsi:type="xsd:string"&gt;Operation &amp;apos;&amp;apos; is not defined in the WSDL for this service&lt;/faultstring&gt;&lt;detail xsi:type="xsd:string"&gt;&lt;/detail&gt;&lt;/SOAP-ENV:Fault&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;'. The remote server returned an error: (500) Internal Server Error. If the service is defined in the current solution, try building the solution and adding the service reference again. </code></pre> <p>solved : well it was easy actually there is two ways either use WCF and change encoding to ISO-8859-1 or change encoding of the web service itself by adding this line <code>$server-&gt;soap_defencoding = 'UTF-8';</code> after creating the soap server</p> </div>

连接到数据库和在Visual Studio Windows窗体中获取数据的问题

<div class="post-text" itemprop="text"> <p>I have a combo box that's supposed to output the main category (has 4 rows) then also output the sub category under it (ex. 3 sub categories under the first main category, 5 sub categories under the second main category and so on). </p> <p>My First Code displays the main category correctly (the combobox has 4 results)</p> <pre><code>private void Form1_Load(object sender, EventArgs e) { sc.Open(); //For Main Category SqlCommand get_maincategory_name = new SqlCommand("SELECT * FROM maincategory", sc); SqlDataReader dr2 = get_maincategory_name.ExecuteReader(); while (dr2.Read()) { comboBox1.Items.Add(dr2["maincategory_name"].ToString()); } sc.Close(); } </code></pre> <p>But I tried inserting another loop for the sub category under the while loop of the main category but all I'm getting on the combo box is the first row of the main category (the combobox only has 1 result which is the first row from the main category table)</p> <p>The code I used was:</p> <pre><code>private void Form1_Load(object sender, EventArgs e) { sc.Open(); //For Main Category SqlCommand get_maincategory_name = new SqlCommand("SELECT * FROM maincategory", sc); SqlDataReader dr2 = get_maincategory_name.ExecuteReader(); while (dr2.Read()) { comboBox1.Items.Add(dr2["maincategory_name"].ToString()); //For Sub Category int got_category_id = Convert.ToInt32(dr2["maincategory_id"]); SqlCommand get_subcategory_name = new SqlCommand("SELECT * FROM subcategory WHERE maincategory_id='got_category_id'", sc); SqlDataReader dr3 = get_subcategory_name.ExecuteReader(); while (dr3.Read()) { comboBox1.Items.Add(dr3["subcategory_name"].ToString()); } } sc.Close(); } </code></pre> <p>The only programming experience I have is on php so I tried creating my intended code on PHP and it worked perfectly but I'm having troubles applying it to C# in Visual Studio, here's my code if you guys are wondering what I'm trying to achieve:</p> <pre><code>echo "&lt;select&gt;"; // FOR MAIN CATEGORY $maincategory_query = mysqli_query($con,"SELECT * FROM maincategory") or mysqli_error(); while($got = mysqli_fetch_assoc($maincategory_query)) { $maincategory_id = $got['maincategory_id']; $maincategory_name = $got['maincategory_name']; echo "&lt;option disabled&gt;$maincategory_name&lt;/option&gt;"; // FOR SUB CATEGORY $subcategory_query = mysqli_query($con,"SELECT * FROM subcategory WHERE maincategory_id='$maincategory_id'") or mysqli_error(); while($got = mysqli_fetch_assoc($subcategory_query)) { $subcategory_id = $got['subcategory_id']; $subcategory_name = $got['subcategory_name']; echo "&lt;option disabled&gt;--$subcategory_name&lt;/option&gt;"; // FOR ITEM $item_query = mysqli_query($con,"SELECT * FROM item WHERE subcategory_id='$subcategory_id'") or mysqli_error(); while($got = mysqli_fetch_assoc($item_query)) { $item_id = $got['item_id']; $item_name = $got['item_name']; echo "&lt;option&gt;----$item_name&lt;/option&gt;"; } } } echo "&lt;/select&gt;"; </code></pre> <p>My Concerns:</p> <ol> <li><p>I don't actually know what's happening on why my second code is only doing the loop once and what's worse is it doesn't even display the sub category (the <code>maincategory_id='got_category_id'</code> beside the WHERE in my sql statement was only a placeholder and I tried replacing it by <code>maincategory_id='1'</code> just to check in hopes of it trying to at least check if it's displaying the sub category to no avail. I actually don't know the proper syntax to insert an integer inside a sql statement in Visual Studio but nevertheless, setting it to a value of '1' still doesn't display anything).</p></li> <li><p>What is the proper syntax on inserting an integer inside a sql statement in Visual Studio? I researched and tried putting the &amp; at the beginning and end of the variable but it isn't working.</p></li> </ol> </div>

结合PHP Webservice和C#Client

<div class="post-text" itemprop="text"> <p>I have a C#/Winforms application using PHP webservices. A first PHP webservice uploadFile.php is used to upload a blob file (by a unix application for example) on a mysql database and another webservice, getFile.php (code below), is used to get the file if a file is available for the client.</p> <p>For the moment the client calls every 5 seconds the webservice. Obviously Apache cannot deal with all the connections and gets slow and is often down or timeout, Today I have counted 2000 connections in 2 minutes, and 100 000 in 25 minutes. 99% of them return no file. </p> <p>So instead of calling every 5 (or 10 or 20 or else) seconds the webservice, I would like the webservice uploadFile to notify the client when a result is available. I'm not familiar with SOAP/REST or any other kind of webservices, and for practical reasons (old versions of the application still running) I could not replace the current webservice with REST. Here is what currently does the webservice getOK.php :</p> <pre><code> if(getJobsForUser($login, $serveur)){ //data is BLOB content $query = "SELECT idjob,fileName,data FROM JobSpool WHERE idcompte=$idcompte LIMIT 1" ; $stmt = $pdo-&gt;query($query); $res = $stmt-&gt;fetch(PDO::FETCH_BOTH); $idjob = $res[0] ; $nomfic = $res[1] ; $data = $res[2] ; //send datas to client echo $nomfic." " ; echo $data ; } function checkJobsforUser($login, $serveur){ global $pdo, $idcompte; $query = "SELECT count(*),c.idcompte FROM Compte as c,Job as j WHERE c.login='$login' AND c.serveur = '$serveur' AND j.idcompte = c.idcompte" ; $stmt = $pdo-&gt;query($query); $results = $stmt-&gt;fetch(PDO::FETCH_BOTH); //print_r($results); $count = $results[0]; $idcompte = $results[1]; //echo "count : $count, idcompte : $idcompte &lt;br/&gt;"; if($count &gt; 0) return true; return false; </code></pre> <p>}</p> <p>C# code :</p> <pre><code>public String getMyFile(){ String nomFicFinal = String.Empty; try { HttpWebRequest hwr; String request = "http://myWebServiceDomain.com/getFile.php?login=myLogin&amp;otherId=myOtherId"; hwr = (HttpWebRequest)HttpWebRequest.Create(request); using (HttpWebResponse hwrep = (HttpWebResponse)hwr.GetResponse()) { //read datas br = new BinaryReader(hwrep.GetResponseStream()); Byte[] tmp = new Byte[256]; int b = br.Read(); while (b != -1) { if (b == 10) break; tmp[indNomFic++] = (Byte)b; b = br.Read(); } //get filename nomFicFinal = System.Text.Encoding.ASCII.GetString(tmp, 0, indNomFic); //if parsed data == "0" nothing returned if (nomFicFinal.Length == 1 &amp;&amp; (nomFicFinal.CompareTo("0") == 0 || nomFicFinal.CompareTo("1") == 0)) { br.Close(); nomFicFinal = ""; } else //we parse the content of the request and we create the file with the name nomFicFinal in ApplicationData { nomFicFinal = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\MyApp\" + nomFicFinal; bw = new BinaryWriter(File.Open(nomFicFinal, FileMode.Create)); tmp = new Byte[1024]; while ((tmp = br.ReadBytes(1024)) != null) { if (tmp.Length == 0) break; bw.Write(tmp); bw.Flush(); } br.Close(); bw.Close(); } } }catch(Exception ex){ //do something } return nomFicFinal; } </code></pre> <p>I have been searching with "callback PHP C#", etc, but I still do not have a clear idea of what to do for the moment.</p> </div>

sql server 数据库排序规则为: Chinese_PRC_CI_AS 但是中文条件查询不加N查不出来的原因?

sql server 数据库排序规则为: Chinese_PRC_CI_AS 但是中文查询必须加N 不加N查不出来 服务器:腾讯虚拟机 windows server 2008 R2 数据库:2008R2 字段数型 nvarchar(100) ![图片说明](https://img-ask.csdn.net/upload/201907/15/1563184220_116753.jpg) ![图片说明](https://img-ask.csdn.net/upload/201907/15/1563184338_738065.jpg) ![图片说明](https://img-ask.csdn.net/upload/201907/15/1563184463_340532.jpg) ![图片说明](https://img-ask.csdn.net/upload/201907/15/1563202015_451248.png)

错误:警告:mysqli_fetch_array()要求参数1为mysqli_result,第15行/var/www/html/data.php中给出布尔值[复制]

<div class="post-text" itemprop="text"> <div class="question-status question-originals-of-duplicate"> <p>This question already has an answer here:</p> <ul> <li> <a href="/questions/2973202/mysql-fetch-array-mysql-fetch-assoc-mysql-fetch-row-mysql-num-rows-etc" dir="ltr">mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or result</a> <span class="question-originals-answer-count"> 32 answers </span> </li> </ul> </div> <p>I am trying to select data from a MySQL table to show data's in my c# datagridview, but I get one of the following error messages:</p> <blockquote> <p>Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /var/www/html/data.php on line 15</p> </blockquote> <p>This is my PHP code:</p> <pre><code>&lt;?php $servername = "********"; $username = "root"; $password = "pws"; $dbname = "dbs"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn-&gt;connect_error) { die("Connection failed: " . $conn-&gt;connect_error); } $sql = "SELECT userid,password,first_name,last_name,role,active FROM aster_users"; $result = mysql_query($sql); while($row = mysqli_fetch_array($result)) { $userid=$row['userid']; $password=$row['password']; $first_name=$row['first_name']; $last_name=$row['last_name']; $role=$row['role']; $active=$row['active']; } $conn-&gt;close(); ?&gt; </code></pre> <p>Help me,</p> </div>

去SQL查询不一致

<div class="post-text" itemprop="text"> <p>I am experiencing some really weird inconsistencies when executing queries, and was wondering if anyone knew why.</p> <p>Imagine I have a struct defined as follows:</p> <pre><code>type Result struct { Afield string `db:"A"` Bfield interface{} `db:"B"` Cfield string `db:"C"` Dfield string `db:"D"` } </code></pre> <p>And a MySQL Table with the following cols:</p> <pre><code>A : VARCHAR(50) B : INT C : VARCHAR(50) D : VARCHAR(50) </code></pre> <p>The query I would like to execute:</p> <blockquote> <p>SELECT A, B, C, D FROM table WHERE A="a"</p> </blockquote> <p>first way it can be executed: </p> <pre><code>db.Get(&amp;result, `SELECT A, B, C, D FROM table WHERE A="a"`) </code></pre> <p>second way it can be executed:</p> <pre><code>db.Get(&amp;result, `SELECT A, B, C, D FROM table WHERE A=?`, "a") </code></pre> <p>The inconsistencies I am experiencing are as follows: When executing the query the first way, the type of Bfield is <code>int</code>. However, when executing the query the second time, it is <code>[]uint8</code>.</p> <p>This outcome is occurring for example when B is 1.</p> <p><strong>Why is the type of Bfield different depending on how the query is executed?</strong></p> <p>connection declaration:</p> <pre><code>// Connection is an interface for making queries. type Connection interface { Exec(query string, args ...interface{}) (sql.Result, error) Get(dest interface{}, query string, args ...interface{}) error Select(dest interface{}, query string, args ...interface{}) error } </code></pre> <p><strong>EDIT</strong></p> <p>This is also happening using the Go database/sql package + driver. The queries below are assigning <code>Bfield</code> to <code>[]uint8</code> and <code>int64</code> respectively.</p> <blockquote> <p>db is of type *sql.DB</p> </blockquote> <p>query 1: </p> <p><code>db.QueryRow(SELECT A, B, C, D FROM table WHERE A="a").Scan(&amp;result.Afield, &amp;result.Bfield, &amp;result.Cfield, &amp;result.Dfield)</code></p> <p>-- &gt; type of <code>Bfield</code> is <code>[]uint8</code></p> <p>query 2:</p> <p><code>db.QueryRow(SELECT A, B, C, D FROM table WHERE A=?, "a").Scan(&amp;result.Afield, &amp;result.Bfield, &amp;result.Cfield, &amp;result.Dfield)</code></p> <p>--&gt; type of <code>Bfield</code> is <code>int64</code></p> <p><strong>EDIT</strong></p> <p>Something else to note, when chaining multiple WHERE clauses, as long as <em>at least</em> 1 is populated using <code>?</code>, the query will return <code>int</code>. Otherwise if they are all populated in the string, it will return <code>[]uint8</code></p> </div>

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

Intellij IDEA 实用插件安利

1. 前言从2020 年 JVM 生态报告解读 可以看出Intellij IDEA 目前已经稳坐 Java IDE 头把交椅。而且统计得出付费用户已经超过了八成(国外统计)。IDEA 的...

搜狗输入法也在挑战国人的智商!

故事总是一个接着一个到来...上周写完《鲁大师已经彻底沦为一款垃圾流氓软件!》这篇文章之后,鲁大师的市场工作人员就找到了我,希望把这篇文章删除掉。经过一番沟通我先把这篇文章从公号中删除了...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

魂迁光刻,梦绕芯片,中芯国际终获ASML大型光刻机

据羊城晚报报道,近日中芯国际从荷兰进口的一台大型光刻机,顺利通过深圳出口加工区场站两道闸口进入厂区,中芯国际发表公告称该光刻机并非此前盛传的EUV光刻机,主要用于企业复工复产后的生产线扩容。 我们知道EUV主要用于7nm及以下制程的芯片制造,光刻机作为集成电路制造中最关键的设备,对芯片制作工艺有着决定性的影响,被誉为“超精密制造技术皇冠上的明珠”,根据之前中芯国际的公报,目...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

百度工程师,获利10万,判刑3年!

所有一夜暴富的方法都写在刑法中,但总有人心存侥幸。这些年互联网犯罪高发,一些工程师高技术犯罪更是引发关注。这两天,一个百度运维工程师的案例传遍朋友圈。1...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《Oracle Java SE编程自学与面试指南》最佳学习路线图2020年最新版(进大厂必备)

正确选择比瞎努力更重要!

字节跳动面试官竟然问了我JDBC?

轻松等回家通知

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

实时更新:计算机编程语言排行榜—TIOBE世界编程语言排行榜(2020年6月份最新版)

内容导航: 1、TIOBE排行榜 2、总榜(2020年6月份) 3、本月前三名 3.1、C 3.2、Java 3.3、Python 4、学习路线图 5、参考地址 1、TIOBE排行榜 TIOBE排行榜是根据全世界互联网上有经验的程序员、课程和第三方厂商的数量,并使用搜索引擎(如Google、Bing、Yahoo!)以及Wikipedia、Amazon、YouTube统计出排名数据。

立即提问
相关内容推荐