从excell到MySQL数据库 [英] From excell to MySQL database
本文介绍了从excell到MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将数据从Excel导入到Mysql数据库
这是我的代码:
C#部分:
private void Button_Click_1( object sender,RoutedEventArgs e)
{
string putanjaExH = tbH.Text;
string putanjaExE = tbE.Text;
if (putanjaExH!= )
{
var wbh = new XLWorkbook(putanjaExH);
var wsh = wbh.Worksheet( Sheet 1\" 中跨度>);
bool ide = true ;
int ih = 5 ;
while (ide)
{
HttpWebRequest httpWReq =(HttpWebRequest)WebRequest.Create( http://admin.apartman-donat.com/refu.php);
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = insert into refh( Gizrade,Investitor,Radni_Zadatak,Predmet_projekta,Vrsta_projekta_K,Vrsta_projekta_O)值(N' + wsh.Cell(ih, 1 )。Value.ToString( ).Replace( 。, )+ ',N' + wsh.Cell(ih, 2 )。值+ ',N' + wsh.Cell(ih, 3 )。值+ ',N' + wsh.Cell(ih, 4 )。值+ ',N' + wsh.Cell(ih, 5 )。值+ ',N' + wsh.Cell(ih , 6 )。值+ ')跨度>;
byte [] data = encoding.GetBytes(postData);
httpWReq.Method = POST;
httpWReq.ContentLength = data.Length;
使用(Stream newStream = httpWReq.GetRequestStream())
{
newStream.Write(data, 0 ,data.Length);
}
WebResponse response = httpWReq.GetResponse();
// 显示状态。
Console.WriteLine(((HttpWebResponse)响应).StatusDescription);
// 获取包含服务器返回内容的流。
流dataStream = response.GetResponseStream();
// 使用StreamReader打开流以便于访问。
StreamReader阅读器= new StreamReader(dataStream);
// 阅读内容。
string responseFromServer = reader.ReadToEnd();
// 显示内容。
MessageBox.Show(responseFromServer);
// 清理流。
reader.Close();
dataStream.Close();
response.Close();
ih = ih + 1 ;
if (wsh.Cell(ih, 1 )。值== )
{
ide = false < /跨度>;
}
}
}
此 .Close();
}
PHP部分:
<?php
$ con = mysql_connect( localhost, test_ref, test);
if (!$ con)
{
die(' 无法连接:' .mysql_error());
}
mysql_select_db( refh,$ con) ;
$ sql = ' $ _ POST [httpWReq]'
if (!mysql_query($ sql,$ con))
{
die(' 错误:' .mysql_error());
}
echo 添加了1条记录;
mysql_close($ con);
?>
响应是:
lt; br>解析错误< / br> :语法错误:意外的T_IF在.....
有人能告诉我我做错了什么?????
解决方案
con = mysql_connect( localhost,< span class =code-string> test_ref, 测试跨度>);
if (!
con)
{
die(' 无法连接:' .mysql_error());
}
mysql_select_db( refh,
CON);
I am trying to import data from Excel to Mysql database
Here is my code:
C# part:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
string putanjaExH = tbH.Text;
string putanjaExE = tbE.Text;
if (putanjaExH != "")
{
var wbh = new XLWorkbook(putanjaExH);
var wsh = wbh.Worksheet("Sheet1");
bool ide = true;
int ih = 5;
while (ide)
{
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create("http://admin.apartman-donat.com/refu.php");
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "insert into refh (Gizrade, Investitor, Radni_Zadatak, Predmet_ projekta, Vrsta_projekta_K, Vrsta_projekta_O) values (N'" + wsh.Cell(ih, 1).Value.ToString().Replace(".", "") + "', N'" + wsh.Cell(ih, 2).Value + "', N'" + wsh.Cell(ih, 3).Value + "', N'" + wsh.Cell(ih, 4).Value + "', N'" + wsh.Cell(ih, 5).Value + "', N'" + wsh.Cell(ih, 6).Value + "')";
byte[] data = encoding.GetBytes(postData);
httpWReq.Method = "POST";
httpWReq.ContentLength = data.Length;
using (Stream newStream = httpWReq.GetRequestStream())
{
newStream.Write(data, 0, data.Length);
}
WebResponse response = httpWReq.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
MessageBox.Show(responseFromServer);
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
ih = ih + 1;
if (wsh.Cell(ih,1).Value=="")
{
ide = false;
}
}
}
this.Close();
}
PHP part:
<?php
$con = mysql_connect("localhost","test_ref","test");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("refh", $con);
$sql='$_POST[httpWReq]'
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
response is:
lt;br> Parse error</br> : Syntax error: unexpected T_IF in .....
Could someone tell me what am I doing wrong?????
解决方案
con = mysql_connect("localhost","test_ref","test"); if (!
con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("refh",
con);
这篇关于从excell到MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文