小编G G*_* Gr的帖子

ExecuteNonQuery:Connection属性尚未初始化?

我的代码中出错:

ExecuteNonQuery:尚未初始化Connection属性.

这可能是由于此代码中的行:

OdbcCommand cmd = new OdbcCommand("INSERT INTO Pictures (UserID, picturepath) VALUES ('" + theUserId + "' , '" + fileuploadpath + "')");
Run Code Online (Sandbox Code Playgroud)

完整代码:

{
    string theUserId = Session["UserID"].ToString();
    {
        OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=root; Password=commando;");
        cn.Open();
    }
    if (FileUploadControl.HasFile)
    {
        try
        {
            string filename = Path.GetFileName(FileUploadControl.FileName);
            //FileUploadControl.SaveAs(Server.MapPath("~/userdata/" + theUserId + "/uploadedimage/") + filename);
            string fileuploadpath = Server.MapPath("~/userdata/" + theUserId + "/uploadedimage/");
            FileUploadControl.SaveAs(Path.Combine(fileuploadpath, filename));
            StatusLabel.Text = "Upload status: File uploaded!";



            OdbcCommand cmd = …
Run Code Online (Sandbox Code Playgroud)

html c# mysql sql asp.net

1
推荐指数
2
解决办法
1万
查看次数

HTML按钮重定向错误

所以我一直在使用BootMetro框架,我遇到了一个问题,试图在图标按钮上创建链接.

作为主标题栏的一部分,我创建了额外的图标.但是我似乎无法弄清楚如何将按钮转换为可重定向的链接:

        <div class="top-info-block">
           <b class="icon-blogger-2" onclick="window.location.href='www.blogger.com'"></b>
           <b class="icon-facebook-2"></b>
           <b class="icon-google-plus-3"></b>
           <b class="icon-youtube"></b>
        </div>
Run Code Online (Sandbox Code Playgroud)

当使用VS2012时,我得到一个页面未找到错误,因为html链接出现:http://localhost:8581/www.blogger.com这是VS2012的一些东西还是我的onclick方法错了?

html hyperlink visual-studio-2012

1
推荐指数
1
解决办法
149
查看次数

会话在当前上下文中不存在?

在尝试实现会话时遇到问题,它说它在当前上下文中不存在我错过了什么?

 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        //database connection string
        OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite; User=x; Password=x; OPTION=3;");
        cn.Open();
        OdbcCommand cmd = new OdbcCommand("Select * from User where username=? and password=?", cn);
        DataSet ds = new DataSet();
        //Select the username and password from mysql database 

        cmd.Parameters.Add("@username", OdbcType.VarChar);
        cmd.Parameters["@username"].Value = this.Login1.UserName;

        cmd.Parameters.Add("@password", OdbcType.VarChar);
        cmd.Parameters["@password"].Value = this.Login1.Password;
        //use asp login control to check username and password

        //Session["UserID"] = "usrName";
        //set the UserID from the User Table …
Run Code Online (Sandbox Code Playgroud)

html c# mysql sql asp.net

0
推荐指数
1
解决办法
976
查看次数

循环插入问题,重新加载页面加载?

我试图实现插入语句并使用我的函数在页面加载中返回.不知道我怎么能插入同时绘制我插入到mysql中的所有内容一次又一次出来?

码:

public partial class UserProfileWall : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string theUserId = Session["UserID"].ToString();
        using (OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=user_name; Password=password_here;"))
        {
            cn.Open();
            using (OdbcCommand cmd = new OdbcCommand("SELECT Wallpostings FROM WallPosting WHERE UserID=" + theUserId + " ORDER BY idWallPosting DESC", cn))

            using (OdbcDataReader reader = cmd.ExecuteReader())
            {
                var divHtml = new System.Text.StringBuilder();
                while (reader.Read())
                {
                    divHtml.Append("<div id=test>");
                    divHtml.Append(String.Format("{0}", reader.GetString(0)));
                    divHtml.Append("</div>");
                }
                test1.InnerHtml = divHtml.ToString();
            }
        } …
Run Code Online (Sandbox Code Playgroud)

html c# mysql sql asp.net

0
推荐指数
1
解决办法
420
查看次数

错误无法从'object'转换为'string'

我在下面的代码中遇到一些错误可以帮助吗?

错误无法从'object'转换为'string''System.IO.File.Exists(string)'的最佳重载方法匹配有一些无效的参数

string theUserId = Session["UserID"].ToString();
OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite2; User=x; Password=x;");
cn.Open();

OdbcCommand sc = new OdbcCommand(string.Format("SELECT picturepath FROM Pictures WHERE UserID ='{0}'", theUserId), cn);
OdbcDataReader reader = sc.ExecuteReader();
while (reader.Read())
{
if (System.IO.File.Exists(reader[0]))
{  // error cannot convert from 'object' to 'string'
   // The best overloaded method match for 'System.IO.File.Exists(string)' has some invalid arguments
    System.IO.File.Delete(reader[0]);
}  // error cannot convert from 'object' to 'string'
   // The best overloaded method match for 'System.IO.File.Delete(string)' …
Run Code Online (Sandbox Code Playgroud)

c# asp.net

0
推荐指数
1
解决办法
2万
查看次数

随机m-by-n矩阵的randperm子集

你如何使用randperm选择m-by-n数据矩阵并输出该随机数据的较小子集?

newfile = randperm(data(m = 2000, n = 3));  %% save random m-by-n data as newfile
Run Code Online (Sandbox Code Playgroud)

random matlab matrix

0
推荐指数
1
解决办法
2165
查看次数

总和不会添加小数位(双打)

当我调用此方法时,它只返回小数位前的数字,例如:

1

2

3

= 6
Run Code Online (Sandbox Code Playgroud)

这很好,但是当我尝试:

1.5

2

3.5

= 6 
Run Code Online (Sandbox Code Playgroud)

我怎样才能得到小数位的总和?

public class Service1 : System.Web.Services.WebService
{

    [WebMethod]


    public string CalculateSum(List<int> listDouble)
    {
        return listDouble.Sum().ToString();


    }
}
Run Code Online (Sandbox Code Playgroud)

}

如果我使用公共字符串CalculateSum(List<double> listDouble),结果始终为0.

无论我输入什么.

这就是我传递信息的方式:

        {
            CalculateSumOfList.ServiceReference1.Service1SoapClient client = new CalculateSumOfList.ServiceReference1.Service1SoapClient();
            CalculateSumOfList.ServiceReference1.ArrayOfInt arrayOfInt = new CalculateSumOfList.ServiceReference1.ArrayOfInt();
            arrayOfInt.AddRange(listDouble.Select(d => (int)d).ToList());

string result = client.CalculateSum(arrayOfInt);
label1.Text = Convert.ToString(result);




                }
Run Code Online (Sandbox Code Playgroud)

c# soap web-services sum

0
推荐指数
1
解决办法
1780
查看次数

正则表达式C#控制台应用程序

如何添加一个接受小数位(5.23)的正则表达式,但是在这样的中断中没有其他内容?即只处理数字和小数位,如果键入或返回除此之外的任何内容,则会抛出错误:

    case 1:
    double[] myArrai1 = new double[3];
    Console.WriteLine("Insert a number");
    myArrai1[0] = double.TryParse(Console.ReadLine()); // no overload method?
     Console.WriteLine("Insert a number");
     myArrai1[1] = double.Parse(Console.ReadLine());
    Console.WriteLine("Insert a number");
    myArrai1[2] = double.Parse(Console.ReadLine());
    break;
Run Code Online (Sandbox Code Playgroud)

干杯伙计们.

Ps不确定如何使用中断编程也必须毫无例外.

c# regex error-handling

0
推荐指数
1
解决办法
1548
查看次数

用户,组和标签数据库设计

我很难尝试为以下场景设计数据库结构:

我的数据库应包含一般用户信息UserID,FirstName,LastName,JoiningDate.

每个用户都可以成为组的一部分.

每个组都附有"标签",可以有多个标签.用户还应该能够返回可用组列表(按标签过滤).

能够搜索组(通过附加到组的标签),并搜索特定用户(按姓氏或唯一ID).).它还应该能够返回可用组列表(按标签过滤)和特定组的成员(按姓氏过滤并按加入日期过滤).

还应该有一种方法可以发现哪些用户组属于多个组(查询"谁是"Bravo组"和"Delta"组的成员),并跟踪组中发送的消息(像一个论坛).

这只是两张桌子吗?或者它应该是三个表...用户,组和标签?自从我做了任何关系数据库之后差不多一年了,我想知道是否有人能展示这个数据库设计的直观表示?

sql database-design

0
推荐指数
1
解决办法
1247
查看次数

输入字符串的格式不正确

下面的代码产生一个错误,说我的输入字符串格式不正确.为什么?

private void button7_Click(object sender, EventArgs e)
{
    string uriAddTagtoGroup = 
      string.Format("http://localhost:8000/Service/AddTagtoGroup/{group}/{tag}",
                    textBox6.Text, textBox7.Text);
    //line above says input string was not in the correct format?
}
Run Code Online (Sandbox Code Playgroud)

c# string.format

0
推荐指数
1
解决办法
572
查看次数