|
|
|
asp.net สอบถามเรื่องการ insert ลง sqlserver ไม่ได้+ภาษา ปัญหาบันทึกภาษาไทย ??? C# |
|
|
|
|
|
|
|
คือ ผมลอง insert เข้าทั้ง 2 ตาราง โดยใช้ oracle และ sqlserverครับ
สำหรับ oracle สำเร็จ ครับ แต่ ตอนนี้ insert เข้า sqlserver มันไม่ยอมเข้า ช่วยดูให้ที ครับ แต่ ถ้าเข้าแล้ว ภาษามันเป็น ??? ครับ ทั้งทีเซ็ต charset=latin1 หรือ charset=tis-620 หรือ charset=utf-8 ก็ยังไม่ได้ ครับ
ส่วน code ผมประมาณนี้ ครับ
Code (C#)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OracleClient;
using System.Data.Odbc;
public partial class AddActivity : System.Web.UI.Page
{
string fileName1;
string filePath1;
protected void btnUpload_Click(object sender, EventArgs e)
{
//Label1.Text = DateTime.Today.ToString();
SaveActivityMysql();
if (SaveActivityMysql() == true)
{
Label1.Text = "Complete add pic";
}
else
Label1.Text = "Error";
//insert_activity
//if ((FileUpload1.FileName != ""))
//{
// string savePath1 = Server.MapPath("uploadImg/activity/");
// fileName1 = FileUpload1.FileName;
// filePath1 = savePath1 + fileName1;
// FileUpload1.SaveAs(filePath1);
// //conn.setgcAttract1 = fileName1;
//}
//InsertData conn = new InsertData();
//OracleCommand comm = new OracleCommand();
//string sql;
//sql = "insert into nattapongs.activity(a_name,a_detail,a_create_date,a_username_create, a_pic_main)";
//sql = sql + " values(:a_name,:a_detail,to_date(:a_create_date,'MM/dd/yyyy'),:a_username_create,:a_pic_main)";
//comm.Parameters.Add(":a_name", OracleType.VarChar).Value = act_name.Text;
//comm.Parameters.Add(":a_detail", OracleType.VarChar).Value = ASPxHtmlEditor1.Html.ToString();
//comm.Parameters.Add(":a_create_date", OracleType.VarChar).Value = DateTime.Today.ToString("MM/dd/yyyy");
//comm.Parameters.Add(":a_username_create", OracleType.VarChar).Value = Session["authen"].ToString();
//comm.Parameters.Add(":a_pic_main", OracleType.VarChar).Value = fileName1;
//if (conn.Savedata(comm, sql))
//{
//SaveActivityMysql();
//Response.Redirect("ListActivity.aspx");
//addsfile();
// }
// else
// Label1.Text = conn.gcErrmsg;
//}
//void addfile()
//{
// try
// {
// // select max a_id
// loaddata Conn2 = new loaddata();
// DataView DvDate = new DataView();
// OracleCommand comm2 = new OracleCommand();
// DvDate = Conn2.GetData_SendParameter(comm2, "select * from nattapongs.activity ORDER BY a_id DESC");
// Label1.Text = DvDate.Table.Rows[0]["a_id"].ToString();
// // Get the HttpFileCollection
// HttpFileCollection hfc = Request.Files;
// for (int i = 0; i < hfc.Count; i++)
// {
// HttpPostedFile hpf = hfc[i];
// if (hpf.ContentLength > 0)
// {
// hpf.SaveAs(Server.MapPath("pic_activity") + "\\" +
// System.IO.Path.GetFileName(hpf.FileName));
// //insert_pic_activity
// InsertData conn3 = new InsertData();
// OracleCommand comm3 = new OracleCommand();
// string sql_pic_activity;
// sql_pic_activity = "insert into nattapongs.activity_pic(ap_pic,ap_a_id)";
// sql_pic_activity = sql_pic_activity + " values(:ap_pic,:ap_a_id)";
// comm3.Parameters.Add(":ap_pic", OracleType.VarChar).Value = System.IO.Path.GetFileName(hpf.FileName);
// comm3.Parameters.Add(":ap_a_id", OracleType.VarChar).Value = DvDate.Table.Rows[0]["a_id"].ToString();
// if (conn3.Savedata(comm3, sql_pic_activity))
// {
// Label1.Text = "Complete add pic";
// }
// else
// Label1.Text = conn3.gcErrmsg;
// }
// }
// }
// catch (Exception ex)
// {
// }
}
Boolean SaveActivityMysql()
{
try
{
string ConnStr = "Driver={MySQL ODBC 3.51 Driver};Server=10.20.20.10;Database=research;uid=research;pwd=irda";
OdbcConnection con = new OdbcConnection(ConnStr);
string xx;
xx = "insert into activity22(topic, detail, dateAct, pic_main, status) values('" + act_name.Text + "','" + ASPxHtmlEditor1.Html.ToString() + "', NOW(),'" + fileName1 + "','N')";
OdbcCommand cmd = new OdbcCommand();
cmd.CommandText = xx;
cmd.Connection = con;
//cmd.Parameters.Add(":gcFullDetail", OdbcType.Text).Value = gcFullDetail;
//cmd.Parameters.Add(new OdbcParameter("@v", gcFullDetail));
//cmd.ExecuteNonQuery();
//(xx, con);
//Label1.Text = xx;
con.Open();
cmd.ExecuteNonQuery();
//con.Close();
return true;
}
catch (Exception e)
{
return false;
}
}
}
Tag : .NET, Ms SQL Server 2008, Oracle, C#
|
|
|
|
|
|
Date :
2011-06-08 10:22:37 |
By :
hero_big |
View :
3299 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|